【发布时间】:2017-08-28 12:25:42
【问题描述】:
我有一个自定义视图(WorldMapView)和一个可绘制的地图(3209x1287,PNG,64 位颜色,1.33M),我得到了
java.lang.RuntimeException: Canvas: 试图绘制过大 (148679388bytes) 位图。
我试着像这样压缩。
WorldMapView worldMapView = (WorldMapView) itemView.findViewById(R.id.map_of_world);
Bitmap bitmap = ((BitmapDrawable) ContextCompat.getDrawable(context, R.drawable.map)).getBitmap();
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
Bitmap decoded = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()));
worldMapView.setImageBitmap(decoded);
但是如果您使用的是PNG格式,那么它不会压缩您的图像,因为PNG是一种无损格式,所以任何人都可以提出解决方案吗?
在此先感谢您。
【问题讨论】:
-
But if you are using PNG format then it will not compress your image because PNG is a lossless format你自己回答了。
标签: android bitmap android-bitmap