节约位图 - IO异常 [英] saving bitmap - IO Exception

查看:217
本文介绍了节约位图 - IO异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我救我的位图,它需要我IOExeption,为什么呢?我不知道:

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的时候我保存:

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?

推荐答案

您包括正确的权限?您将需要写入到外部存储权限。

Are you including the correct permissions? You will need the write to external storage permission.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

修改

尝试放置文件的目录中的SD卡,如:

Try placing the file within a directory on the SDCARD, such as:

File f = new File(Environment.getExternalStorageDirectory() 
      + File.separator + "test" + File.Separator + "mind");

这篇关于节约位图 - IO异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆