Android canvas save always java.io.IOException: open failed: ENOENT (No such file or directory) -
i have canvas application. i'm trying create signature app canvas
+ ontouchlistener
.
this save method, try save signature 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 save", 5000).show(); showmenubar(); } }
i don't know why, errors or enters catch
statement error:
java.io.ioexception: open failed: enoent (no such file or directory)
try way
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 save", 5000).show(); } }
update
file mfolder = new file(extr + "/imotax/capture/spop/ttd/image"); //replace file mfolder = new file(extr + "/imotax");
Comments
Post a Comment