0
我想使用gzip將位圖轉換爲base64。Android - 將壓縮位圖(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();
}
會這樣代碼會使圖像丟失數據,還是在服務器端?
,對我沒有工作。仍然在圖像上灰色 – 2014-10-29 20:09:04
已更新的示例。 – Simon 2014-10-29 20:26:06
你是我的英雄:)完美的工作。非常感謝你。 – 2014-10-29 20:30:10