- 转自:http://blog.csdn.net/csh159/article/details/8835477
- /**
- * 图片转成string
- *
- * @param bitmap
- * @return
- */
- public static String convertIconToString(Bitmap bitmap)
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();// outputstream
- bitmap.compress(CompressFormat.PNG, 100, baos);
- byte[] appicon = baos.toByteArray();// 转为byte数组
- return Base64.encodeToString(appicon, Base64.DEFAULT);
- }
- /**
- * string转成bitmap
- *
- * @param st
- */
- public static Bitmap convertStringToIcon(String st)
- {
- // OutputStream out;
- Bitmap bitmap = null;
- try
- {
- // out = new FileOutputStream("/sdcard/aa.jpg");
- byte[] bitmapArray;
- bitmapArray = Base64.decode(st, Base64.DEFAULT);
- bitmap =
- BitmapFactory.decodeByteArray(bitmapArray, 0,
- bitmapArray.length);
- // bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
- return bitmap;
- }
- catch (Exception e)
- {
- return null;
- }
- }
Android Bitmap与String互转
最新推荐文章于 2024-08-11 03:48:54 发布