【问题标题】:Getting full-sized image from the camera does not work on Galaxy S从相机获取全尺寸图像在 Galaxy S 上不起作用
【发布时间】:2010-09-27 16:31:12
【问题描述】:

我在从三星 Galaxy S 的内置相机应用程序中捕捉图像时遇到问题。

我的应用上有一个按钮,按下时会启动相机:

ContentValues values = new ContentValues();
values.put(Images.Media.MIME_TYPE, "image/jpeg");

mPicUri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);

intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mPicUri.getPath());
startActivityForResult(intent, REQ_CODE_TAKE_PIC);

根据我在 interwebz 上阅读的内容,我可以使用传递给意图的 URI 来获取全尺寸的刚刚拍摄的照片。所以我的 onActivityResult 上有这个:

Uri selectedImage = mPicUri;
String[] filePathColumn = {MediaStore.Images.Media.DATA};

Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();

int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();

然后使用变量 filePath,我将图像设置在 ImageView 中。我没有得到图像,当我单步执行代码时,我发现 BitmapFactory.decodeFile() 正在返回 null

Bitmap chosenPic = BitmapFactory.decodeFile(filePath);

所以我尝试了更多的调试。我发现 mPicUri 返回一个看似有效的 URI,例如:content://media/external/images/media/90。拍照后用户选择保存图片后,光标解析为以下文件路径:/sdcard/DCIM/Camera/1285601413961.jpg。虽然没有位图被解码,但是当我浏览画廊时,我刚拍的照片就在那里。所以我试着看一下那张图片的 URI,这就是我得到的:

URI is:           content://media/external/images/media/91
File path is:     /sdcard/DCIM/Camera/2010-09-27 23.30.30.jpg

因此,看起来我从 mPicUri 获得的值不是将要使用的 final URI。

我在这里错过了一步吗?我真正想做的就是检索刚刚拍摄的照片的文件。

提前致谢, 扎拉。

【问题讨论】:

  • 有没有找到解决这个问题的方法?
  • 嗨@OhDannyBoy!抱歉,离开 StackOverflow 有一段时间了。我想我想出了一个办法,必须在家里检查我的代码。会告诉你的!
  • 此资源包含检索图像的代码。 kevinpotgieter.wordpress.com/2011/03/30/… 但非常感谢您的帮助!
  • 你对你的问题有任何答案吗?我在银河迷你标签中遇到同样的问题,如果有任何想法请帮助我。

标签: android camera


【解决方案1】:

您是否尝试在拍照前和拍照后都指定文件?

public static File getTempFile() {
    //it will return /sdcard/image.jpg
    final File path = new File(Environment.getExternalStorageDirectory(), "MyApp");
    if (!path.exists()) {
        path.mkdir();
    }
    return new File(path, "image.jpg");
}

我正在使用这个函数来获取和设置文件路径。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-07
    • 1970-01-01
    • 2018-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多