Android: Bitmap to Byte Array and back: SkImageDecoder::Factory returned null Android: Bitmap to Byte Array and back: SkImageDecoder::Factory returned null android android

Android: Bitmap to Byte Array and back: SkImageDecoder::Factory returned null


You are passing Bitmap into Intent and get bitmap in next activity from bundle, but the problem is if your Bitmap/Image size is big at that time the image is not load in next activity.

Use below 2 Solutions to solve this issue.

1) First Convert Image into Byte Array and then pass into Intent and in next activity get byte array from Bundle and Convert into Image(Bitmap) and set into ImageView.

Convert Bitmap to Byte Array:-

Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);ByteArrayOutputStream stream = new ByteArrayOutputStream();bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);byte[] byteArray = stream.toByteArray();

Pass byte array into intent:-

Intent intent = new Intent(this, NextActivity.class);intent.putExtra("picture", byteArray);startActivity(intent);

Get Byte Array from Bundle and Convert into Bitmap Image:-

Bundle extras = getIntent().getExtras();byte[] byteArray = extras.getByteArray("picture");Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);ImageView image = (ImageView) findViewById(R.id.imageView1);image.setImageBitmap(bmp);

2) First Save image into SDCard and in next activity set this image into ImageView.


The following method works perfectly with me, give it a try..

public byte[] convertBitmapToByteArray(Context context, Bitmap bitmap) {    ByteArrayOutputStream buffer = new ByteArrayOutputStream(bitmap.getWidth() * bitmap.getHeight());    bitmap.compress(CompressFormat.PNG, 100, buffer);    return buffer.toByteArray();}


try this:

  bmBef = BitmapFactory.decodeFile("/mnt/sdcard/Debug/001.png", bmo);  ByteArrayOutputStream baos= new ByteArrayOutputStream();  bmBef .compress(Bitmap.CompressFormat.PNG, 100, baos);  byte[] byteArray = baos.toByteArray();