0

I am new to android,I developed one sample application which load the image from sd card and display as a bitmap image using image view controll. Now i want to modify my application like load the bmp from byte array i have the raw image ,width and height ,do any one have sample for this?

Mr.Cool
  • 1,525
  • 10
  • 32
  • 51

3 Answers3

5

Use below Code for Convert Byte Array to Bitmap and display this bitmap into ImageView.

Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap(bmp);

and see below SO link for more information.

Convert ByteArray to Bitmap

Community
  • 1
  • 1
Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128
1

I think you can use BitmapFactory.

public static Bitmap decodeByteArray (byte[] data, int offset, int length)

For more info, look here

Renjith
  • 5,783
  • 9
  • 31
  • 42
0

if your image is in Drawable folder try this code

    Drawable drawable= getResources().getDrawable(R.drawable.yourimage);

    //Type cast to BitmapDrawable
    Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();

    //Write a compressed version of the bitmap to the specified outputstream via compress method.    
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
    byte[] buffer  = stream.toByteArray();
Renjith
  • 5,783
  • 9
  • 31
  • 42
NARESH REDDY
  • 682
  • 4
  • 11