android 保存bitmap到SD卡
16lz
2021-01-24
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;}
更多相关文章
- 【链接】android图片压缩总结
- android 获取手机图片裁剪后分享 2
- android 图片压缩方法
- android 怎么把网络图片生成一个Bitmap显示在ImageView中
- Android将String保存为SD卡中TXT文件的方法
- Android(安卓)水波纹扩散效果
- android模仿微信朋友圈图片预览转场缩放动画
- Android中常用的Intent