简体   繁体   English

BItmap:内存不足错误。 在android中压缩后如何获取原始图像大小

[英]BItmap:out of memory error. how to get the original image size after compressing it in android

I have drawn an image manually on bitmap. 我已经在位图上手动绘制了图像。 But it has shown out of memory error. 但是它显示出内存不足错误。 I, then reduced the size of the image which shows me the compressed form of the image. 我,然后减小图像的大小,向我显示图像的压缩形式。 I need the original size of the image to be displayed which is then showing out of memory error. 我需要显示图像的原始大小,然后显示内存不足错误。 Kindly, help me out in resolving the issue. 请帮助我解决问题。 I am enclosing the part of the code too. 我也附上了代码的一部分。

ImageView iv1 = new ImageView(mcontext); ImageView iv1 =新的ImageView(mcontext);

BitmapFactory.Options options = new BitmapFactory.Options(); BitmapFactory.Options options =新的BitmapFactory.Options();
options.inSampleSize = 2; options.inSampleSize = 2;

BitmapFactory.decodeFile(pageViewManager.getPenToolPath() + pageViewManager.getCurrentPageIndex() + ".jpg"); BitmapFactory.decodeFile(pageViewManager.getPenToolPath()+ pageViewManager.getCurrentPageIndex()+“ .jpg”);

bmp = BitmapFactory.decodeFile(pageViewManager.getPenToolPath() + pageViewManager.getCurrentPageIndex() + ".jpg", options); bmp = BitmapFactory.decodeFile(pageViewManager.getPenToolPath()+ pageViewManager.getCurrentPageIndex()+“ .jpg”,选项);

iv1.setImageBitmap(bmp); iv1.setImageBitmap(bmp);

The memory space used by an uncompressed picture is easy to calculate: it's the number of pixels*the color depth, the number of pixels itself is height*width. 未压缩图片使用的存储空间很容易计算:它是像素数*颜色深度,像素数本身是高度*宽度。 For example, for an image of 1000*800 in 24 bits (3 bytes), the memory size will be: 例如,对于24位(3字节)的1000 * 800图像,内存大小将为:

1000*800*3=2400000 bytes or 2,4 Mb 1000 * 800 * 3 = 2400000字节或2.4 Mb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM