所以我想爲我使用base64編碼的圖像取一個字符串,並將其變成我可以在ImageView中使用的圖像。編碼它的代碼是:base64中的編碼圖像回到圖像
final Bitmap bitmap = BitmapFactory.decodeFile(fileUri.getPath(), options);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
image_str = Base64.encodeToString(b, Base64.DEFAULT);
我假設它會將image_str轉換回byteArray,然後返回到位圖?
我不是很熟悉base64的功能,所以我想我會在這裏問我搜索,以便在相同的時間內完成更多的工作。
謝謝你在前進,
泰勒
編輯:我發現這段代碼,但圖像不顯示出來,並logcat的說,解碼返回false:
byte[] imageBytes=Base64.decode(imageString,Base64.NO_WRAP);
InputStream in = new ByteArrayInputStream(imageBytes);
Bitmap b = BitmapFactory.decodeStream(in);
你會BASE64將字符串解碼爲字節,然後將字節轉換回位圖。 –
我發現這個: byte [] imageBytes = Base64.decode(imageString,Base64.NO_WRAP); InputStream in = new ByteArrayInputStream(imageBytes); 位圖b = BitmapFactory.decodeStream(in); 但它不工作,它說在logcat解碼返回false,然後不顯示圖像,但我確實看到字符串在那裏,並正確 – TylerM