Deepi
Deepi

Reputation: 188

convert the byteArray to bitmap in android?

In my web service images are stored in byteArray format.i want to convert the bitmap image.

i have attached my code here .

  BufferedInputStream bufferedInputStream = new BufferedInputStream(AndroidJSONParsingActivity.inputStream);
             Bitmap bmp = BitmapFactory.decodeStream(bufferedInputStream);
             ByteArrayOutputStream companylogo = new
             ByteArrayOutputStream();
             ImageView image=new ImageView(this);
             image.setImageBitmap(bmp);

Upvotes: 1

Views: 10295

Answers (2)

Numair
Numair

Reputation: 1062

Try this,

// Camera arg conversion to Bitmap
Bitmap background = BitmapFactory.decodeByteArray(Your_byte_array_image, 0,
                            Your_byte_array_image.length);
Bitmap back = Bitmap.createBitmap(background.getWidth(),
                        background.getHeight(), Bitmap.Config.ARGB_8888);

Use this bitmap.

Upvotes: 1

Nirav Ranpara
Nirav Ranpara

Reputation: 13785

Bitmap bitmap = BitmapFactory.decodeFile("/path/images.jpg");
ByteArrayOutputStream blob = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0 /*ignored for PNG*/, blob);
byte[] bitmapdata = blob.toByteArray();
//if bitmapdata is the byte array then getting bitmap goes like this

Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapdata , 0, bitmapdata .length);
Returns The decoded bitmap, or null if the image could not be decode.

Upvotes: 2

Related Questions