Android中JPEG到字节数组的图像转换
我想在android中将JPEG图像转换为字节数组。我正在使用以下代码:Android中JPEG到字节数组的图像转换,android,Android,我想在android中将JPEG图像转换为字节数组。我正在使用以下代码: if (PhotoScreen.st_bitPicture != null) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); boolean b = PhotoScreen.st_bitPicture.compress(CompressFormat.JPEG,
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);
}
但它正在压缩图像。如果不压缩图像,我该怎么办?当你说压缩时,你的意思是将其转换为base 64吗?。您已经有了一个字节数组,然后在base 64中对其进行编码。你期望的输出是什么
PhotoScreen.st_bitPicture.compress(CompressFormat.JPEG, 100, bos);
创建内存中的JPEG图像JPEG压缩
bos.toByteArray()
使用JPEG数据创建字节数组。这就是你想要的
Base64.encodeToString(bos.toByteArray(), Base64.DEFAULT);
将此数据编码到base 64。如果您不想使用base 64,请省略该步骤。如果您想要任何其他输出,如字节数组转换为十六进制的字符串,请改为这样做。它将以不同的像素大小发送到服务器。假设我将其设置为300*400,则它将存储为200*225。Bitmap.compress不会调整图像大小。这一定是在创建位图时发生的。