將字串轉換成Bitmap型別 或者 將Bitmap轉換成字串

zhouxuebao87發表於2015-09-17
public static Bitmap stringtoBitmap(String string) {
// 將字串轉換成Bitmap型別
Bitmap bitmap = null;
try {
byte[] bitmapArray;
bitmapArray = Base64.decode(string, Base64.DEFAULT);
bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0,
bitmapArray.length);
} catch (Exception e) {
e.printStackTrace();
}


return bitmap;
}


public static String bitmaptoString(Bitmap bitmap) {


// 將Bitmap轉換成字串
String string = null;
ByteArrayOutputStream bStream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 40, bStream);
byte[] bytes = bStream.toByteArray();
string = Base64.encodeToString(bytes, Base64.DEFAULT);
return string;


}

相關文章