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

处理大尺寸图片导致的Canvas异常
在尝试绘制尺寸为6000*4000且颜色深度为4的大型图片时,遇到了java.lang.RuntimeException: Canvas:trying to draw too large的错误,导致系统崩溃。问题涉及到140Mb和200Mb的两张图片。

加载一个 尺寸特别大的图 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'

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dl6655

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值