保存位图 - IO 异常
当我保存位图时,它会将我带到 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
我拥有我需要的用户权限() 但无论如何它都不起作用。有什么问题吗?
When I save my bitmap, it takes me to IOExeption, why? I dont know:
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 when I save:
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
I have the user permission that I need() But it doesn't work anyway. What's the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通过使用 canvas.drawBitmap 并提供矩阵来尝试此缩放位图。
try this scale bitmaps by using canvas.drawBitmap with providing matrix.
您是否包含正确的权限?您将需要写入外部存储的权限。
编辑
尝试将文件放置在 SDCARD 上的某个目录中,例如:
Are you including the correct permissions? You will need the write to external storage permission.
Edit
Try placing the file within a directory on the SDCARD, such as:
加载听起来像是 BitmapFactory.decodeFile 的工作。另外,我会直接压缩到您的文件输出流:
Loading sounds like a job for BitmapFactory.decodeFile. Also, I would compress directly to your file output stream: