I want to convert JPEG image to Byte Array in android. I am using the below code:
if (PhotoScreen.st_bitPicture != null)
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
boolean b = PhotoScreen.st_bitPicture.compress(CompressFormat.JPEG, 100, bos);
Log.w("test2", "BOOLEAN BOOLEAN BOOLEAN BOOLEAN :"+b);
m_base64EncodedImage = Base64.encodeToString(bos.toByteArray(), Base64.DEFAULT);
}
But it is compressing t开发者_如何转开发he image. How can i do without compressing the image?
When you say "compressing", do you mean "convert it to base 64?". You already have a byte array, and then you encode it in base 64. What is your desired output?
PhotoScreen.st_bitPicture.compress(CompressFormat.JPEG, 100, bos);
Creates an in-memory JPEG image (JPEG compressed).
bos.toByteArray()
Creates a byte array with the JPEG data. That's what you want.
Base64.encodeToString(bos.toByteArray(), Base64.DEFAULT);
Encodes this data to base 64. Just omit that step if you don't want base 64. If you want any other output (like a string with the byte array converted to hexadecimal), then do that instead.
精彩评论