我想將位圖保存到文件,然後將其保存在SD卡上。 這裏是我的代碼:無法在SD卡中創建文件
String path = Environment.getExternalStorageDirectory().toString();
File file = new File(path, "Jhs"+".jpg");
file.mkdir();
OutputStream fOut;
try {
fOut = new FileOutputStream(file);
BitmapMatrix convMatrix = new BitmapMatrix(0);
convMatrix.result.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
fOut.flush();
fOut.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
另外這個代碼是不延伸Activity.I我只是給這個信息想,也許有一些問題,與此一類。 這裏是我的logcat
05-01 18:00:22.555: W/System.err(31392): java.io.FileNotFoundException: /mnt/sdcard/Jhs.jpg (Permission denied)
05-01 18:00:22.555: W/System.err(31392): at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
05-01 18:00:22.555: W/System.err(31392): at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
05-01 18:00:22.555: W/System.err(31392): at java.io.FileOutputStream.<init>(FileOutputStream.java:94)
05-01 18:00:22.555: W/System.err(31392): at java.io.FileOutputStream.<init>(FileOutputStream.java:66)
05-01 18:00:22.555: W/System.err(31392): at com.example.imageprocess.BitmapMatrix.computeConvolution3x3(BitmapMatrix.java:123)
05-01 18:00:22.555: W/System.err(31392): at com.example.imageprocess.MainActivity.sharpen(MainActivity.java:105)
05-01 18:00:22.555: W/System.err(31392): at com.example.imageprocess.MainActivity.onCreate(MainActivity.java:51)
05-01 18:00:22.555: W/System.err(31392): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
05-01 18:00:22.555: W/System.err(31392): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836)
05-01 18:00:22.555: W/System.err(31392): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
05-01 18:00:22.555: W/System.err(31392): at android.app.ActivityThread.access$1500(ActivityThread.java:135)
05-01 18:00:22.555: W/System.err(31392): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
05-01 18:00:22.555: W/System.err(31392): at android.os.Handler.dispatchMessage(Handler.java:99)
05-01 18:00:22.565: W/System.err(31392): at android.os.Looper.loop(Looper.java:150)
05-01 18:00:22.565: W/System.err(31392): at android.app.ActivityThread.main(ActivityThread.java:4389)
05-01 18:00:22.565: W/System.err(31392): at java.lang.reflect.Method.invokeNative(Native Method)
05-01 18:00:22.565: W/System.err(31392): at java.lang.reflect.Method.invoke(Method.java:507)
05-01 18:00:22.565: W/System.err(31392): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
05-01 18:00:22.565: W/System.err(31392): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
05-01 18:00:22.565: W/System.err(31392): at dalvik.system.NativeStart.main(Native Method)
@湯姆有沒有在格式多點編輯它被遺棄沒有意義的分辨率的老問題,而且是最有可能的許多其他的副本 - 你結束將它拉到頁面的頂部,分散注意力的問題。 – 2015-01-02 17:17:12