从相机拍照并从图库中选择并在图像视图中显示

take picture from camera and choose from gallery and display in Image view(从相机拍照并从图库中选择并在图像视图中显示)

本文介绍了从相机拍照并从图库中选择并在图像视图中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从图库中拍摄照片并将其设置在我的 ImageView 中,以及我想从相机中拍摄照片并将其设置到我的同一个图像视图中.

I want to take photos from gallery and set it in my ImageView as well as I want to take photo from camera and set it into my same Image View.

我非常坚持这一点.

谁能帮帮我?

谢谢.

推荐答案

你可以这样处理你的camera view click:

You can handle your camera view click this way:

cameraImageView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
            startActivityForResult(intent, 0);

        }
    });

在您拍摄图像后返回时在您的活动中执行此操作.

Do this in your activity when you return after capturing image.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode == 0)
    {
        if(data != null)
        {
            Bitmap photo = (Bitmap) data.getExtras().get("data");
            photo = Bitmap.createScaledBitmap(photo, 80, 80, false);
            imageView.setImageBitmap(photo);
        }
        else{
        }
    }
}

这篇关于从相机拍照并从图库中选择并在图像视图中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:从相机拍照并从图库中选择并在图像视图中显示

基础教程推荐