簡體   English   中英

Android將字節數組轉換為Bitmap的最佳方法?

[英]Android Best way to convert byte array to Bitmap?

我知道為什么會出現OutOfMemoryError異常。但是有任何最好的方法將字節數組轉換為Bitmap.And我使用下面的代碼,但是當大字節時它強制關閉app並給出OutOfMemoryError Exception。

我有API它只是返回字節數組沒有別的。

Bitmap bmp = BitmapFactory.decodeByteArray(bytearray, 0, bytearray.length);
Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapbytes , 0, bitmapbytes .length);

返回已解碼的位圖,如果圖像無法解碼,則返回null。

這對我有用:照片是順便說一下的一串圖像。

byte[] imgbytes = Base64.decode(photo, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(imgbytes, 0,
imgbytes.length);
imageupload.setImageBitmap(bitmap);

您可能必須使用以下方法( DOC ,相同的方法,但使用options參數):

public static Bitmap decodeByteArray (byte[] data, int offset, int length, BitmapFactory.Options opts)

並使用options參數進行播放。 希望這會幫助你=)

您可能希望使用AQuery庫來加載圖像,這將幫助您調整大小,查看等,並避免最常見的內存泄漏。 可以在此處找到此工具: http//code.google.com/p/android-query/

暫無
暫無

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

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