Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to convert image into byte in android and that byte pass to web services
Posted

Hi,

I assume you mean a byte array and not a byte, because converting an image to a byte does not make much sense.

Have a look here:
http://stackoverflow.com/a/10514374[^]
Try this:
Java
// convert from bitmap to byte array
public byte[] getBytesFromBitmap(Bitmap bitmap) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.JPEG, 70, stream);
    return stream.toByteArray();
}
 
Share this answer
 
v2
Comments
ridoy 3-Jun-14 16:14pm    
my 5.
Thomas Daniels 4-Jun-14 9:46am    
Thank you!
ProgramFOX already gave you a good solution. I want to extend that. See these 2 links with the above one:
Convert image to byte array[^]
Convert Image into ByteArray [^]
 
Share this answer
 
Comments
Thomas Daniels 4-Jun-14 9:47am    
Good links, a 5.
ridoy 4-Jun-14 9:55am    
Thank you, but probably you forgot to give that vote, :p.
Thomas Daniels 4-Jun-14 10:16am    
No, I didn't forget to vote. It's a bug: it takes some time before the stars show up. You can find a post about it in the Bugs & Suggestions forum. For me, they show up fine now.
ridoy 4-Jun-14 13:51pm    
yes, i found it now. Anyway, thanks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900