在Android中获取用相机拍摄的图片的图像Uri +缩略图 [英] Get image Uri + thumbnail of the picture shot with camera in Android

查看:51
本文介绍了在Android中获取用相机拍摄的图片的图像Uri +缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用我用内置 Android 相机制作的图片来更新 ImageView.我使用以下代码:

I want to update an ImageView with a picture I make with the build-in Android camera. I use the following code:

void getPhoto() {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(intent, TAKE_PICTURE);
    }

之后,我通过以下方式获取照片:

After that I acquire the photo with:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == TAKE_PICTURE) {
            Bitmap photo = (Bitmap) data.getExtras().get("data");
            ImageView photoView = (ImageView) findViewById(R.id.photoId);
            photoView.setImageBitmap(photo);
            }
        }

但是使用此代码,无论我做什么,我都只能获得我制作的照片的缩略图 - 我的问题是如何获得刚刚制作的照片的 Uri,以便不使用缩略图而是使用原始图像?

But with this code no matter what I do I only get a thumbnail of the photo I made - my question is how can I get the Uri of the photo just made in order to work not with the thumbnail but with the original image?

附言.我实际上需要照片的缩略图,但我也需要原始照片的 Uri.

Ps. I actually need the thumbnail of the photo but I need the Uri of the original photo too.

推荐答案

我把我自己的URI放在intent里告诉它保存在哪里,然后你就知道它在哪里了,不知道有没有其他方法.为您的文件创建一些字段.

I put my own URI in the intent to tell it where to save, then you know where it is, not sure there is any other way. Create some fields for your file.

private String imagePath = "/sdcard/Camera/test.jpg";
private File originalFile;

然后初始化文件.

originalFile = new File(imagePath);

现在使用 Intent 启动相机应用,将 URI 作为额外内容传递.

Now start the Camera app with the intent, passing the URI as an extra.

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    Uri outputFileUri = Uri.fromFile(originalFile);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
    startActivityForResult(intent, RESULT_CAPTURE_IMAGE); 

在 onActivityResult() 中提取 URI

In the onActivityResult() extract the URI

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            if (requestCode == RESULT_CAPTURE_IMAGE && resultCode == Activity.RESULT_OK) {
        mBitmap = BitmapFactory.decodeFile(originalImagePath, BitmapFactoryOptions);  //set whatever bitmap options you need.

因此,您现在可以使用 createBitmap 构建位图,或者根据需要使用文件路径

So you can now build a bitmap using createBitmap or use file path for whatever you need

这篇关于在Android中获取用相机拍摄的图片的图像Uri +缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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