Android Bitmap与String互转(转)
1 /** 2 * 图片转成string 3 * 4 * @param bitmap 5 * @return 6 */ 7 public static String convertIconToString(Bitmap bitmap) 8 { 9 ByteArrayOutputStream baos = new ByteArrayOutputStream();// outputstream 10 bitmap.compress(CompressFormat.PNG, 100, baos); 11 byte[] appicon = baos.toByteArray();// 转为byte数组 12 return Base64.encodeToString(appicon, Base64.DEFAULT); 13 14 } 15 16 /** 17 * string转成bitmap 18 * 19 * @param st 20 */ 21 public static Bitmap convertStringToIcon(String st) 22 { 23 // OutputStream out; 24 Bitmap bitmap = null; 25 try 26 { 27 // out = new FileOutputStream("/sdcard/aa.jpg"); 28 byte[] bitmapArray; 29 bitmapArray = Base64.decode(st, Base64.DEFAULT); 30 bitmap = 31 BitmapFactory.decodeByteArray(bitmapArray, 0, 32 bitmapArray.length); 33 // bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); 34 return bitmap; 35 } 36 catch (Exception e) 37 { 38 return null; 39 } 40 }
联系方式:emhhbmdfbGlhbmcxOTkxQDEyNi5jb20=