我有一个画布应用程序。我正在尝试创建一个签名应用程序Canvas
+ onTouchListener
.
这是我的保存方法,我尝试将签名保存到图像中:
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
出现此错误的语句:
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();
}
}
UPDATE
File mFolder = new File(extr + "/imotax/capture/spop/ttd/image"); //replace with
File mFolder = new File(extr + "/imotax");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)