0
try {
FileOutputStream out = new FileOutputStream("p1");
pictureTaken.compress(Bitmap.CompressFormat.PNG, 90, out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}

        case R.id.open:
        ImageView im = (ImageView) findViewById(R.id.im);
        try {
            FileInputStream in = new FileInputStream("p1");
            BufferedInputStream buf = new BufferedInputStream(in);
            byte[] bitMapA= new byte[buf.available()];
            buf.read(bitMapA);
            Bitmap bM = BitmapFactory.decodeByteArray(bitMapA, 0, bitMapA.length);
            im.setImageBitmap(bM);
            if (in != null) {
            in.close();
            }
            if (buf != null) {
            buf.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        break;

两者都尝试过,但他们没有通过调试,他们只是抓住了......我在网上获得了大部分这些部分并根据我的需要对其进行了修改,但即便如此,这一切都是有道理的,并且在我的脑海中起作用. 只是不明白为什么它会引发异常。

4

1 回答 1

2

这听起来像是在 Android 上,并且从您使用的路径 ( p1) 中,您只是想保存到应用程序运行文件夹中的文件。从广义上讲,您不能写入任何目录。你会想做这样的事情:

FileOutputStream out = openFileOutput ("p1", MODE_WORLD_WRITABLE);

在第一个代码块中,然后:

FileInputStream in = openFileInput("p1");

在第二个代码块中。

于 2011-05-22T05:52:01.777 回答