Android中的位图大小以编程方式与Vs.亚行规模

时间:2012-06-30 18:30:48

标签: java android image

我已经搜索了这个,我发现对于api小于12,通常使用的是bitmap.getrowbytes * bitmap.getheight;

但是,对于图像,我获得以下内容:

mBitmap.getRowBytes() = 320
mBitmap.getHeight() = 100
mBitmap.getWidth() = 80.

因此根据上面的公式我得到32,000。

然而,当我检查文件时,我正在使用

从adb读取位图图像
ls -l

我知道它的大小是90Kb。

我正在阅读如下图片:

        Uri chosenImageUri = data.getData();
        if (chosenImageUri != null) {
            try {
       InputStream photoStream = getContentResolver().openInputStream(chosenImageUri);
          BitmapFactory.Options opts = new BitmapFactory.Options(); 
              opts.inSampleSize = 4;
              Bitmap mBitmap = BitmapFactory.decodeStream(photoStream,null, opts);
          photoStream.close();

} 
}

为什么结果不同?谢谢。

2 个答案:

答案 0 :(得分:1)

好的,我只是明白发生了什么。如果它可以帮助任何人,我会发布这个。

这样做的原因是我使用bitmapfactoryoptons和insamplesize = 4。

会发生什么

例如,inSampleSize == 4返回的图像是原始宽度/高度的1/4,像素数的1/16。任何值< = 1都被视为与1相同。

如上所述here

答案 1 :(得分:0)

映像在RAM上占用的内存量与磁盘上的内存量不同。在RAM中,图像的内存消耗可以通过公式pixels*3检查(如果是RGB)和pixels*4(如果是ARGB)。 width*height可以找到像素数。您的图片必须具有Alpha通道,80*100*4 = 32,000。请注意,这是以字节为单位,要以kB或MB为单位,您需要将其除以1024和1024 * 1024。