• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
张纯睿
博客园    首页    新随笔    联系   管理    订阅  订阅

Highgui.imwrite("/data/pic1111.png", mat)失败,且找不到报错

——》 Highgui.imwrite("/data/pic1111.png", mat)失败,且找不到报错。
ok --》直接使用以下代码,自己保存mat,从而可以跟踪问题。
// java自己写的 实现方法
Bitmap bmp_new = Bitmap.createBitmap(mat.cols(), mat.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(mat, bmp_new, false); // Mat->Bitmap

File f = new File("pic1111.jpg");
if (f.exists()) {
f.delete();
}
try {
FileOutputStream out = new FileOutputStream(f);
bmp_new.compress(Bitmap.CompressFormat.PNG, 90, out);
out.flush();
out.close();
Log.i("SaveMat", "已经保存");
} catch (FileNotFoundException e) {
// TODO: handle exception
Toast.makeText(this.context, e.getMessage()+"error1", 1).show();
} catch (IOException e) {
// TODO Auto-generated catch block
Toast.makeText(this.context, e.getMessage()+"error2", 1).show();
}
——》 跟踪到问题 "Read-only file system"
ref:http://stackoverflow.com/questions/10787942/android-read-only-file-system-ioexception
找到问题:Because you are trying to write the file to root, you need to pass the file path to your file directory.
File f = new File("pic1111.jpg");
FileOutputStream out = new FileOutputStream(f);
改为
File f = new File(context.getFilesDir().getPath().toString()+"/pic1111.jpg");
FileOutputStream out = new FileOutputStream(f);
或者(!!推荐使用)
FileOutputStream out = context.openFileOutput("pic11121.jpg", Context.MODE_PRIVATE);

posted @ 2014-12-30 10:27  张纯睿  阅读(483)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3