简体   繁体   English

检查imageview中的图片是否从相机或图库中捕获

[英]Check if picture in imageview was captured from camera or gallery

I am able to capture an image from gallery or camera and put it in imageview with following code: 我能够从图库或照相机中捕获图像,并使用以下代码将其放入imageview中:

1. Capture image from gallery or camera: 1.从图库或照相机中捕获图像:

private void captureImageInitialization() {

    final String[] items = new String[] { "Take from camera",
            "Select from gallery" };
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.select_dialog_item, items);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    builder.setTitle("Select Image");
    builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) { // pick from
                                                                // camera
            if (item == 0) {
                Intent intent = new Intent(
                        "android.media.action.IMAGE_CAPTURE");
                startActivityForResult(intent, PICK_FROM_CAMERA);

            } else {
                // pick from file
                /**
                 * To select an image from existing files, use
                 * Intent.createChooser to open image chooser. Android will
                 * automatically display a list of supported applications,
                 * such as image gallery or file manager.
                 */
                Intent intent = new Intent();

                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);

                startActivityForResult(Intent.createChooser(intent,
                        "Complete action using"), PICK_FROM_FILE);
            }
        }
    });

    dialog = builder.create();
}

2. Show in imageview: 2.在imageview中显示:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode != RESULT_OK)
            return;

        switch (requestCode) {
        case PICK_FROM_CAMERA:

            mImageCaptureUri = data.getData();
            imagepath = getPath(mImageCaptureUri);
            bitmap = BitmapFactory.decodeFile(imagepath);

            mImageView.setImageBitmap(bitmap);
            // Log.d("camera ---- > ", "" + data.getExtras().get("data"));
            new ProcessUploadAvatar2().execute();

            break;

        case PICK_FROM_FILE:
            /**
             * After selecting image from files, save the selected path
             */
            mImageCaptureUri = data.getData();
            imagepath = getPath(mImageCaptureUri);
            bitmap2 = BitmapFactory.decodeFile(imagepath);
            mImageView.setImageBitmap(bitmap2);

            break;

        }
    }

Now my question is how to check if the image in the imageview has been taken by camera or gallery beyond the onActivityResult() method? 现在我的问题是如何检查图像视图中的图像是否已由onActivityResult()方法之外的相机或图库拍摄? I try to implement something like this: 我尝试实现这样的事情:

public void NetAsync() {

        if (mImageView.getDrawable() != null) {

            if (mImageView = bitmap) {
                new NetCheck().execute();
            } else if (mImageView = bitmap2) {
                new ProcessUploadAvatar2().execute();
            }
        }

    }

您可以通过在onActivityResult()中对请求代码进行一次检查来轻松获得此代码...我的意思是您在调用相机/图库意图时发送的那些请求代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 图片从图库到图像视图 - Picture from gallery to an imageview 将内置相机拍摄的图片设置为ImageView - setting picture captured by built-in camera into an ImageView 显示从相机拍摄的照片,或从图库中选择图像视图中其他活动后拍摄的照片 - display the photo captured from camera or after selecting it from gallery on another activity in imageview 来自相机或画廊的图片? - Picture coming from camera or gallery? 将相机中的图片加载到ImageView中 - Loading picture from camera into ImageView 相机图片从存储到imageview? - Camera picture from storage to imageview? 如何将相机拍摄的图像存储在图库中? - How to store image captured from camera in gallery? 从相机捕获的图像不在imageview android中显示 - Image captured from camera not displaying in imageview android 在imageview中使用时从相机或图库拍摄的照片,其方向发生变化,有时在Android中垂直拉伸 - Picture taken from camera or gallery when using in imageview its orientation getting changed, and sometimes vertically stretched in Android 如何recyclerview适配器imageview选择打开相机获取图像并从照片库中选择一张图片? - how to recyclerview adapter imageview select open camera get image and choose a picture from the photo gallery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM