Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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[]..

like image 892
Dhrumil Shah - dhuma1981 Avatar asked Nov 04 '22 11:11

Dhrumil Shah - dhuma1981


1 Answers

Use ByteBuffer:

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

and use array the way you want...

like image 138
ALiGOTec Avatar answered Nov 09 '22 05:11

ALiGOTec