android 保存bitmap到SD卡

/**      * 保存bitmap到SD卡      * @param bitName 保存的名字      * @param mBitmap 图片对像      * return 生成压缩图片后的图片路径      */@SuppressLint("SdCardPath") public static String saveMyBitmap(String bitName,Bitmap mBitmap) {File f = new File("/sdcard/" + bitName + ".png");try {f.createNewFile();} catch (IOException e) {System.out.println("在保存图片时出错:" + e.toString());}FileOutputStream fOut = null;try {fOut = new FileOutputStream(f);} catch (FileNotFoundException e) {e.printStackTrace();}try {mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);} catch (Exception e) {return "create_bitmap_error";}try {fOut.flush();} catch (IOException e) {e.printStackTrace();}try {fOut.close();} catch (IOException e) {e.printStackTrace();}return "/sdcard/" + bitName + ".png";}


/** * 保存bitmap到SD卡 * @param bitmap * @param imagename */public static String saveBitmapToSDCard(Bitmap bitmap, String imagename) {String path = "/sdcard/" + "img-" + imagename + ".jpg";FileOutputStream fos = null;try {fos = new FileOutputStream(path);if (fos != null) {bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);fos.close();}return path;} catch (Exception e) {e.printStackTrace();}return null;}



更多相关文章

  1. 【链接】android图片压缩总结
  2. android 获取手机图片裁剪后分享 2
  3. android 图片压缩方法
  4. android 怎么把网络图片生成一个Bitmap显示在ImageView中
  5. Android将String保存为SD卡中TXT文件的方法
  6. Android(安卓)水波纹扩散效果
  7. android模仿微信朋友圈图片预览转场缩放动画
  8. Android中常用的Intent

随机推荐

  1. Android免Root权限Hook系统函数修改程序
  2. Android(安卓)缓存
  3. android面试题总结加强再加强版(四)
  4. 让最新的 Android(安卓)Q Beta 3 强制重
  5. android动画深入解析--仿58底部导航的ite
  6. Android(安卓)表格控件-动态实现表格效果
  7. React Native之Image组件使用时Android和
  8. Android技巧:画九宫格
  9. Nine Patch PNG in Android!
  10. android 4.0以上设置wifi静态IP以及DNS的