gpt4 book ai didi

android - 使用相机 Intent 拍照并保存到文件

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:42:05 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Android Camera - Save image into a new folder in SD Card

我正在尝试拍照并将其保存到文件中。问题来了,我正在尝试将位图保存到文件中。这是我的代码:

private void takePic() {
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, 2);


}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 2) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
ImageView test = (ImageView) findViewById(R.id.test);
test.setImageBitmap(photo);

try {
FileOutputStream out = new FileOutputStream("filename");
photo.compress(Bitmap.CompressFormat.JPEG, 90, out);
} catch (Exception e) {
e.printStackTrace();
}
}
}

以及 logcat 中的异常:

04-02 14:46:51.975: W/IInputConnectionWrapper(2225): showStatusIcon on inactive InputConnection
04-02 14:46:56.135: W/System.err(2225): java.io.FileNotFoundException: /filename (Read-only file system)
04-02 14:46:56.135: W/System.err(2225): at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
04-02 14:46:56.145: W/System.err(2225): at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
04-02 14:46:56.145: W/System.err(2225): at java.io.FileOutputStream.<init>(FileOutputStream.java:94)
04-02 14:46:56.145: W/System.err(2225): at java.io.FileOutputStream.<init>(FileOutputStream.java:165)
04-02 14:46:56.145: W/System.err(2225): at java.io.FileOutputStream.<init>(FileOutputStream.java:144)

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com