1

Bitmapファイルにオブジェクトを書きたいと思います。これは私のコードです:

File f = new File(path + "-bw.jpg");
OutputStream fileStream = new BufferedOutputStream(new FileOutputStream(path + "-bw.jpg"));
image.getBitmap().compress(Bitmap.CompressFormat.JPEG, 100, fileStream);
fileStream.close();

以下はスタックトレースです。

1-11 09:56:05.553: D/dalvikvm(277): GC_EXTERNAL_ALLOC freed 385 objects / 15832 bytes in 69ms
11-11 09:56:05.733: D/dalvikvm(277): GC_EXTERNAL_ALLOC freed 32 objects / 34048 bytes in 51ms
11-11 09:56:05.923: E/Save error(277): /mnt/sdcard/Water lilies-bw.jpg (Permission denied)
11-11 09:56:05.923: E/Save error(277): java.io.FileNotFoundException: /mnt/sdcard/Water lilies-bw.jpg (Permission denied)
11-11 09:56:05.923: E/Save error(277):  at org.apache.harmony.luni.platform.OSFileSystem.openImpl(Native Method)
11-11 09:56:05.923: E/Save error(277):  at org.apache.harmony.luni.platform.OSFileSystem.open(OSFileSystem.java:152)
11-11 09:56:05.923: E/Save error(277):  at java.io.FileOutputStream.<init>(FileOutputStream.java:97)
11-11 09:56:05.923: E/Save error(277):  at java.io.FileOutputStream.<init>(FileOutputStream.java:168)
11-11 09:56:05.923: E/Save error(277):  at java.io.FileOutputStream.<init>(FileOutputStream.java:147)
11-11 09:56:05.923: E/Save error(277):  at it.bwpp.activity.ConvertPictureActivity.convertImage(ConvertPictureActivity.java:75)
11-11 09:56:05.923: E/Save error(277):  at it.bwpp.activity.ConvertPictureActivity.access$6(ConvertPictureActivity.java:68)
11-11 09:56:05.923: E/Save error(277):  at it.bwpp.activity.ConvertPictureActivity$1.onClick(ConvertPictureActivity.java:58)
11-11 09:56:05.923: E/Save error(277):  at android.view.View.performClick(View.java:2408)
11-11 09:56:05.923: E/Save error(277):  at android.view.View$PerformClick.run(View.java:8816)
11-11 09:56:05.923: E/Save error(277):  at android.os.Handler.handleCallback(Handler.java:587)
11-11 09:56:05.923: E/Save error(277):  at android.os.Handler.dispatchMessage(Handler.java:92)
11-11 09:56:05.923: E/Save error(277):  at android.os.Looper.loop(Looper.java:123)
11-11 09:56:05.923: E/Save error(277):  at android.app.ActivityThread.main(ActivityThread.java:4627)
11-11 09:56:05.923: E/Save error(277):  at java.lang.reflect.Method.invokeNative(Native Method)
11-11 09:56:05.923: E/Save error(277):  at java.lang.reflect.Method.invoke(Method.java:521)
11-11 09:56:05.923: E/Save error(277):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-11 09:56:05.923: E/Save error(277):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-11 09:56:05.923: E/Save error(277):  at dalvik.system.NativeStart.main(Native Method)
11-11 09:56:05.923: I/save image(277): End save image...

エラーはどこにありますか? ありがとう!

4

1 に答える 1

13

android.permission.WRITE_EXTERNAL_STORAGEAnroidManifest.xml にアクセス許可を追加するのを忘れていたと思います。

于 2011-11-11T09:27:22.670 に答える