Android canvas始终保存java.io.IOException:打开失败:ENOENT(无此类文件或目录) [英] Android canvas save always java.io.IOException: open failed: ENOENT (No such file or directory)
本文介绍了Android canvas始终保存java.io.IOException:打开失败:ENOENT(无此类文件或目录)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个画布应用程序.我正在尝试使用Canvas
+ onTouchListener
创建一个签名应用.
I have a canvas application. I'm trying to create a signature app with Canvas
+ onTouchListener
.
这是我的保存方法,在这里我尝试将签名保存到图像:
This is my save method, where I try to save the signature to an image:
private void save() {
hideMenuBar();
View content = this;
content.setDrawingCacheEnabled(true);
content.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
Bitmap bitmap = content.getDrawingCache();
String path = Environment.getExternalStorageDirectory().getAbsolutePath();
String imgPath = path+"/imotax/capture/spop/ttd/image" + "temp" + ".jpg";
File file = new File(imgPath);
FileOutputStream ostream;
try {
file.createNewFile();
ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.JPEG, 100, ostream);
ostream.flush();
ostream.close();
Toast.makeText(getContext(), "image saved", 5000).show();
} catch (Exception e) {
e.printStackTrace();
Log.i("ttd", e.toString());
Toast.makeText(getContext(), "Failed To Save", 5000).show();
showMenuBar();
}
}
我不知道为什么,但是它总是错误或输入catch
语句并出现以下错误:
I don't know why, but it always errors or enters the catch
statement with this error:
java.io.IOException: open failed: ENOENT (No such file or directory)
推荐答案
尝试这种方式
private void save() {
try {
hideMenuBar();
View content = this;
content.setDrawingCacheEnabled(true);
content.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
Bitmap bitmap = content.getDrawingCache();
String extr = Environment.getExternalStorageDirectory().toString();
File mFolder = new File(extr + "/imotax/capture/spop/ttd/image");
if (!mFolder.exists()) {
mFolder.mkdir();
}
String s = "tmp.png";
File f = new File(mFolder.getAbsolutePath(), s);
FileOutputStream fos = null;
fos = new FileOutputStream(f);
bitmap.compress(CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
bitmap.recycle();
Toast.makeText(getContext(), "image saved", 5000).show();
} catch (Exception e) {
Toast.makeText(getContext(), "Failed To Save", 5000).show();
}
}
更新
File mFolder = new File(extr + "/imotax/capture/spop/ttd/image"); //replace with
File mFolder = new File(extr + "/imotax");
这篇关于Android canvas始终保存java.io.IOException:打开失败:ENOENT(无此类文件或目录)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文