android 从data目录拷贝图片到sdcard, Bitmap 转成 image

13 篇文章 0 订阅
12 篇文章 0 订阅

android 从data目录拷贝图片到sdcard, Bitmap 转成 image

        /**
	 * @author zhang a nan
	 * @email 191118015@qq.com <br>
	 *        --------------------------------------
	 * @param FileName
	 *            FileName的实例值
	 *            "/data/data/com.thinkzheng.game.zuobudao/files/87249_70986_93311.jpg"
	 * @return
	 */
	public String copy(String FileName) {
		// 获取文件名称
		String res = FileName.substring(FileName.lastIndexOf("/") + 1);
		// sdcard下保存文件的目录
		String dir = mContext.getString(R.string._mnt_sdcard_)
				+ "zuobudao/screenshot/";
		// 文件路径
		String path = dir + res;
		try {
			// 读取文件
			Bitmap bmp = BitmapFactory.decodeFile(FileName);

			File file = new File(dir);
			// 判断目录是否存在
			if (!file.exists())
				// 创建目录
				file.mkdirs();

			file = new File(path);
			// 创建新文件
			file.createNewFile();
			// 创建一个输出流
			FileOutputStream fos = new FileOutputStream(file);
			bmp.compress(CompressFormat.PNG, 100, fos);
			// 在数据缓存中数据满了之后刷新该缓存,
			fos.flush();
			// 关闭流
			fos.close();
			// 返回该文件的最新路径
			return path;
		} catch (Throwable t) {
			t.printStackTrace();
			return null;
		}
	}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值