获取Android的拍摄与摄像头的图片图像乌里+缩略图 [英] Get image Uri + thumbnail of the picture shot with camera in Android

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

问题描述

我想更新与图片我做的内置的Andr​​oid摄像头的ImageView的。 我用下面的code:

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);
            }
        }

但有了这个code,无论我做什么,我只得到我发照片的缩略图 - 我的问题是我如何能得到刚才为了照片的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的意图告诉它在哪里保存,那么你知道它在哪里,不知道有什么别的办法。 为您的文件创建一些字段。

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;

,然后初始化文件。

Then initialize the file.

originalFile = new File(imagePath);

现在开始的意图的摄像头应用程序,传递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的拍摄与摄像头的图片图像乌里+缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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