日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android bitmap string,Android Bitmap到Base64字符串(Android Bitmap to Base64 String)

發布時間:2023/12/4 Android 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android bitmap string,Android Bitmap到Base64字符串(Android Bitmap to Base64 String) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Android Bitmap到Base64字符串(Android Bitmap to Base64 String)

如何將一個大的Bitmap(用手機相機拍攝的照片)轉換為Base64 String?

How do I convert a large Bitmap (photo taken with the phone's camera) to a Base64 String?

原文:https://stackoverflow.com/questions/9224056

更新時間:2019-11-21 18:31

最滿意答案

使用以下方法將位圖轉換為字節數組:

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);

byte[] byteArray = byteArrayOutputStream .toByteArray();

從字節數組中使用以下方法對base64進行編碼

String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);

use following method to convert bitmap to byte array:

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);

byte[] byteArray = byteArrayOutputStream .toByteArray();

to encode base64 from byte array use following method

String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);

2013-12-12

相關問答

假設您的圖像數據位于一個名為myImageData的字符串中,以下內容應該可以做到這一點: byte[] imageAsBytes = Base64.decode(myImageData.getBytes(), Base64.DEFAULT);

ImageView image = (ImageView)this.findViewById(R.id.ImageView);

image.setImageBitmap(

BitmapFactory.deco

...

public static String encodeToBase64(Bitmap image, Bitmap.CompressFormat compressFormat, int quality)

{

ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();

image.compress(compressFormat, quality, byteArrayOS);

return Base64.enc

...

使用以下方法將位圖轉換為字節數組: ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);

byte[] byteArray = byteArrayOutputStream .toByteArray();

從字節數組中使用以下方法對base64進行編碼 St

...

您只需使用其他內置方法即可恢復代碼。 byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);

Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);

You can just basically revert your code using some other built in meth

...

我發現了問題。 問題在于logcat來自我復制編碼字符串的地方。 Logcat沒有顯示整個String,因此破碎的字符串沒有為我解碼圖像。 因此,當我將編碼的字符串直接傳遞給解碼函數時,圖像是可見的。 I have found out the problem. The problem was with the logcat from where i was copying the encoded string. Logcat didn't display the entire String so

...

試試這個位圖; public Bitmap convert(String img){

byte[] b = Base64.decode(img, Base64.DEFAULT);

return BitmapFactory.decodeByteArray(b, 0, b.length);

}

而這就是String public String convert(Bitmap bm, int quality){

ByteArrayOutputStream baos = n

...

表示圖像的前三個base64字符串解碼正常。 但是接下來的四個產生了一個bad base-64在線的捕獲 byte[] decodedString = Base64.decode(photo, Base64.URL_SAFE);

之前我說過。 如果你愿意的話 byte[] decodedString = Base64.decode(photo, Base64.DEFAULT);

然后沒有捕獲。 所有7個base64字符串解碼都可以。 The first three base64 strings

...

如果你已經在文件中有了它,那么就沒有理由對它進行解壓縮然后重新壓縮 - 這可能是導致錯誤的原因,因為每次壓縮都是有損的并且會導致數據進一步丟失。 如果您已有圖像文件,請將其作為原始字節和Base64讀取。 If you already have it in the file, there is no reason to decompress it then recompress it- which may be the cause of your errors, as each compressi

...

你可以使用httpmime庫上傳任何文件(圖像,音頻,視頻等..)請參考下面的代碼。 HttpClient httpClient = new DefaultHttpClient();

HttpContext localContext = new BasicHttpContext();

HttpPost postRequest = new HttpPost(your url);

MultipartEntity reqEntity = new MultipartEntity(

Htt

...

只需將base64字符串轉換為位圖,而不是使用下面的代碼將該位圖加載到imageview中 byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);

Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);

image.setImageBitmap(decodedByte);

Just con

...

總結

以上是生活随笔為你收集整理的android bitmap string,Android Bitmap到Base64字符串(Android Bitmap to Base64 String)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。