编辑后的图片保存到SD卡 [英] Save an edited image to the SD card
问题描述
我从库中打开图像,调整其大小,并试图挽救调整版本的应用程序数据文件,这样我就可以抓住它的未来。我的问题是我一直得到一个FileNotFoundException异常,当我尝试将其与输入流写入。
这是它的尝试写太多的文件。 /mnt/sdcard/Android/data/foundcake.myslide/files/IMG_20100918_133128.png
我错过任何重要的步骤吗?
文件storagePath =新的文件(Environment.getExternalStorageDirectory()+/Android/data/foundcake.myslide/files/);
storagePath.mkdirs(); Debug.print(存储路径+ storagePath); 模式模式= Pattern.compile(/([^/]+)\\\\.[^/]+$);
匹配匹配= pattern.matcher(文件路径);
字符串文件名=;
而(matcher.find()){
文件名= matcher.group(1);
} Debug.print(文件名+文件名); 文件缓存=新的文件(storagePath,文件名+png格式); Debug.print(NEW FILE+ cached.toString()); 尝试{
FileOutputStream中出=新的FileOutputStream(缓存);
bitmap.com preSS(Bitmap.Com pressFormat.PNG,100,出);
}赶上(例外五){
e.printStackTrace();
}
所需
<使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAGE/>
哎呦。
I'm opening an image from the gallery, resizing it, and attempting to save the resized version to the apps data file so I can grab it in future. My problem is I keep getting a FileNotFoundException when I try to write it with an input stream.
This is the file it's trying to write too. "/mnt/sdcard/Android/data/foundcake.myslide/files/IMG_20100918_133128.png"
Am I missing any important steps here?
File storagePath = new File(Environment.getExternalStorageDirectory() + "/Android/data/foundcake.myslide/files/");
storagePath.mkdirs();
Debug.print("STORAGE PATH " + storagePath);
Pattern pattern = Pattern.compile("/([^/]+)\\.[^/]+$");
Matcher matcher = pattern.matcher(filePath);
String fileName = "";
while (matcher.find()) {
fileName = matcher.group(1);
}
Debug.print("FILE NAME " + fileName);
File cached = new File(storagePath, fileName + ".png");
Debug.print("NEW FILE " + cached.toString());
try {
FileOutputStream out = new FileOutputStream(cached);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
} catch (Exception e) {
e.printStackTrace();
}
Needed
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Whoops.
这篇关于编辑后的图片保存到SD卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!