java.lang.RuntimeException: Canvas:trying to draw too large(......)bitmap

加载一个 尺寸特别大的图 6000*4000*4 多的一个图;造成 绘制 时候 系统崩了,这是一张140Mb和一张200Mb的图

 
 
java.lang.RuntimeException: Canvas: trying to draw too large(213828900bytes) bitmap.
java.lang.RuntimeException: Canvas: trying to draw too large(112265312bytes) bitmap.
尝试用使用如下方法就可以解决了
Bitmap image = BitmapFactory.decodeFile(file.getPath());//loading the large bitmap is fine. int w = image.getWidth();//get widthint h = image.getHeight();//get heightint aspRat = w / h;//get aspect ratioint W = [handle width management here...];//do whatever you want with width. Fixed, screen size, anythingint H = w * aspRat;//set the height based on width and aspect ratio
Bitmap b = Bitmap.createScaledBitmap(image, W, H, false);//scale the bitmapimageView.setImageBitmap(b);//set the image viewimage = null;//save memory on the bitmap called 'image'

猜你喜欢

转载自blog.csdn.net/dl6655/article/details/79061707
今日推荐