【发布时间】:2014-10-30 04:53:30
【问题描述】:
我正在尝试使用 gzip 将位图转换为 base64。
我尝试了here 的解决方案,但出现此错误GZIP 无法解析或不是字段
我下面的解决方案正在运行,但图像在底部被剪切
这是我的代码:
Bitmap myBitmap = BitmapFactory.decodeFile("\path\to\file.jpg");
ByteArrayOutputStream stream=new ByteArrayOutputStream();
GZIPOutputStream gzipOstream=null;
try {
gzipOstream=new GZIPOutputStream(stream);
} catch (IOException e) {
e.printStackTrace();
}
myBitmap.compress(Bitmap.CompressFormat.JPEG, 100, gzipOstream);
byte[] byteArry=stream.toByteArray();
String encodedImage = Base64.encodeToString(byteArry, Base64.NO_WRAP);
try {
gzipOstream.close();
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
此代码会使图像丢失数据还是服务器端的东西?
【问题讨论】:
标签: android bitmap base64 gzip