5

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

4
  • 2
    please share some code what you have done Commented Nov 9, 2011 at 12:32
  • For what reason you need to convert and what you have already tried? Commented Nov 9, 2011 at 12:38
  • 1
    I have ans for this in iphone... Sorry not for Android... Commented Nov 10, 2011 at 6:32
  • Do you have a feed-back on the answer? Commented Oct 1, 2012 at 14:50

1 Answer 1

2

Use ByteBuffer:

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

and use array the way you want...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.