我需要帮助来理解BitmapRegionDecoder以及如何使用。我无法弄清楚如何计算屏幕的x和y来剪切图像以制作网格。我想在图像点击上剪切一个特定的网格。我该怎么做。此图像很大,通常图像大小会因不同情况而异。
PFB代码无法正常工作并且无法解码区域异常:
try {
InputStream in = null;
URL url = new URL("http://www.libpng.org/pub/png/img_png/pnglogo-blk.png");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try
{
in = new BufferedInputStream(urlConnection.getInputStream());
}catch (Exception e){
e.printStackTrace();
}
BitmapFactory.Options options = new BitmapFactory.Options();
BitmapRegionDecoder regionDecoder = BitmapRegionDecoder.newInstance(in, false);
Bitmap img = regionDecoder.decodeRegion(new Rect(100,100,100,100), options);
imageView.setImageBitmap(img);
} catch (IOException e) {
e.printStackTrace();
}
答案 0 :(得分:0)
试试这个:
URL url = new URL("http://www.libpng.org/pub/png/img_png/pnglogo-blk.png");
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
imageView.setImageBitmap(bmp);