因为要保存图片跟H5交互 H5给出了Base64的文件流 1:将base64转化成bitmap
//将base64转换成图片并加载 public static Bitmap stringToBitmap(String string) { Bitmap bitmap = null; try { byte[] bitmapArray = Base64.decode(string.split(",")[1], Base64.DEFAULT); bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length); } catch (Exception e) { e.printStackTrace(); } return bitmap; }
2:将batmap保存在本地 private void saveToLocal(Bitmap bitmap, String bitName) throws IOException { File file = new File("/sdcard/DCIM/Camera/" + bitName + ".jpg"); if (file.exists()) { file.delete(); } FileOutputStream out; try { out = new FileOutputStream(file); if (bitmap.compress(Bitmap.CompressFormat.PNG, 90, out)) { out.flush(); out.close(); //保存图片后发送广播通知更新数据库 Intent intent = new Intent(Intent.ACTI