簡體   English   中英

將.gif圖像轉換為base64以上傳到服務器

[英]Convert .gif image to base64 to upload to server

我正在嘗試將動畫gif編碼為base64,因此可以將其上傳到服務器。 我已經在使用靜態圖像了,但是如果我嘗試使用GIF,它根本就行不通。 我從Intent圖像選擇器中獲取圖像,並將其放入ImageView中。

這是我用來將圖像編碼為base64的代碼:

Bitmap bitmap = ((BitmapDrawable) ((ImageView) nextChild).getDrawable()).getBitmap();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 60, baos);
byte[] imginbyte = baos.toByteArray();
value = Base64.encodeToString(imginbyte, Base64.DEFAULT);

嘗試這個 :

byte[] imginbyte = Base64.decodeBase64(bitmap.getImageBase64());
new FileOutputStream("image2.gif");
write(imginbyte);
close();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM