阅读背景:

android 保存bitmap到SD卡

来源:互联网 

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



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: