I am trying to compress an image and output the size of the compressed and original images to Logcat (using Bitmap.getAllocationByteCount()
). However, the compressed and original image sizes are always the same despite a visible change in the compressed image's quality. I am making use of the Picasso SDK to read images from a resource and eventually load a bitmap returned by the callback in the Target
class into an ImageView
.
Here is my code:
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);
}
}
I tried compressing JPEGs and PNG with a 0 compression factor, however the sizes are always the same. What am I doing wrong ? An explanation or even a solution would be most appreciated. I am trying to reduce the size of the Bitmap before loading it into an ImageView
. Thanks in advance.
Edit:
I tried using getByteCount()
and getRowBytes() * getHeight()
in place of getAllocationByteCount() and the results are always the same.