【发布时间】:2012-01-28 23:42:19
【问题描述】:
当我保存位图时,它会将我带到 IOExeption,为什么?我不知道:
static Bitmap[] bmp = new Bitmap[4];
public static void save(FileIO files, int location) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
try {
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + "test" + File.separator + "mind");
Log.d("path", f.toString());
f.createNewFile();
// write the bytes in file
FileOutputStream fo = new FileOutputStream(f);
bmp[location].compress(Bitmap.CompressFormat.PNG, 100, bytes);
fo.write(bytes.toByteArray());
fo.close();
Log.d("fisnish", "Bitmap saved");
} catch (IOException e) {
Log.d("IO", e.getMessage());
}
}
我保存时的Logcat:
01-29 00:53:58.020: DEBUG/path(8222): /mnt/sdcard/test/mind
01-29 00:53:58.060: DEBUG/IO(8222): Permission denied
01-29 00:53:58.240: DEBUG/dalvikvm(8222): GC_EXTERNAL_ALLOC freed 7K, 53% free 2563K/5379K, external 5375K/6713K, paused 178ms
01-29 00:54:02.029: DEBUG/dalvikvm(4723): GC_EXPLICIT freed 7K, 53% free 2643K/5511K, external 1625K/2137K, paused 3421ms
我有我需要的用户权限()但它无论如何都不起作用。有什么问题?
【问题讨论】:
-
您发现此代码有任何异常。
-
是的,当我尝试使用 bmp[i] 时,它给了我一个 NullPointerException
-
不确定,但你检查过你的文件是否在你的位置。
-
in = new FileInputStream(Environment.getExternalStorageDirectory() + File.separator + "numbers" + i);这是什么?
-
这里是不是你的位图,你可以手动检查一下吗..
标签: android bitmap save sd-card ioexception