Dhrumil Shah - dhuma1981
Dhrumil Shah - dhuma1981

Reputation: 15789

convert Bitmap to Byte array without compress method in android

I want to upload an image to my website via my android app so for that i want to convert my image to Byte[].

i have used the following code but not work for me..

    ByteArrayOutputStream bos=new ByteArrayOutputStream();
    bm.compress(CompressFormat.JPEG,0, bos);
    byte[] data=bos.toByteArray();

So please share with me any other way to convert an Image to Byte[]..

Upvotes: 5

Views: 3990

Answers (1)

ALiGOTec
ALiGOTec

Reputation: 347

Use ByteBuffer:

 array = new byte[w*h*4];
 Buffer dst = ByteBuffer.wrap(array);
 bmp.copyPixelsToBuffer(dst);

and use array the way you want...

Upvotes: 2

Related Questions