Android - 压缩和未压缩图像的大小相同

Android - size of compressed and uncompressed images the same

我正在尝试压缩图像并将压缩图像和原始图像的大小输出到 Logcat(使用 Bitmap.getAllocationByteCount())。但是,尽管压缩图像的质量发生明显变化,但压缩图像和原始图像的大小始终相同。我正在使用 Picasso SDK 从资源中读取图像,并最终将 Target class 中的回调返回的位图加载到 ImageView.

这是我的代码:

public class MainActivity extends ActionBarActivity {

ImageView imageView1;
private Target target;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    imageView1 = (ImageView)findViewById(R.id.image_view_1);

    target = new Target(){

        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {

            Log.v("BITMAP BEFORE",Integer.valueOf(bitmap.getAllocationByteCount()).toString());

            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

            bitmap.compress(Bitmap.CompressFormat.JPEG,0,outputStream);

            Bitmap decodedMap = BitmapFactory.decodeStream(new ByteArrayInputStream(outputStream.toByteArray()));

            imageView1.setImageBitmap(decodedMap);

            Log.v("BITMAP AFTER",Integer.valueOf(decodedMap.getAllocationByteCount()).toString());

        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {

            Log.v("ON BITMAP FAILED", "ON BITMAP FAILED");
        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {

            Log.v("ON PREPARE LOAD","ON PREPARE LOAD");
        }
    };

    loadImage();
}


private void loadImage(){

    Picasso.with(getApplicationContext()).load(R.drawable.smiley).into(target);
}
}

我尝试使用 0 压缩因子压缩 JPEG 和 PNG,但大小始终相同。我究竟做错了什么 ?将不胜感激解释甚至解决方案。我试图在将位图加载到 ImageView 之前减小位图的大小。提前致谢。

编辑: 我尝试使用 getByteCount()getRowBytes() * getHeight() 代替 getAllocationByteCount(),结果始终相同。

However, the compressed and original image sizes are always the same despite a visible change in the compressed image's quality.

Bitmap在RAM中的大小与图像是否压缩或图像质量无关。它完全取决于分辨率(宽度、高度)和位深度。 getAllocationByteCount() returns Bitmap.

在 RAM 中的大小

压缩和图像质量会影响位图图像在磁盘上的大小