简体   繁体   English

在Android中使用相机活动

[英]Using the camera activity in Android

If you want to use the built-in camera activity which uses the native Android camera, simply do the following. 如果您想使用使用原生Android相机的内置相机活动,只需执行以下操作即可。

Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);   
        this.startActivityForResult(camera, PICTURE_RESULT);

You want to get the images back from the nifty camera you displayed -- but how? 你想从你展示的漂亮相机中取回图像 - 但是如何?

If you want to get the image back in its full glory, pass in a uri to the Intent within the EXTRA_OUTPUT extra. 如果你想让图像恢复光彩,请将uri传递给EXTRA_OUTPUT额外的Intent。 If you're fine with a smallish bitmap (and you should be), just call the intent as normal. 如果你对一个小的位图很好(你应该这样),只需正常调用意图。

Now you have two options, deal with the uri of the image that is returned in the EXTRA_OUTPUT extra, or do the following in your onActivityResult method: 现在您有两个选项,处理EXTRA_OUTPUT额外返回的图像的uri,或者在onActivityResult方法中执行以下操作:

if (requestCode == PICTURE_RESULT) //
             if (resultCode == Activity.RESULT_OK) {
                // Display image received on the view
                 Bundle b = data.getExtras(); // Kept as a Bundle to check for other things in my actual code
                 Bitmap pic = (Bitmap) b.get("data");

                 if (pic != null) { // Display your image in an ImageView in your layout (if you want to test it)
                     pictureHolder = (ImageView) this.findViewById(R.id.IMAGE);
                     pictureHolder.setImageBitmap(pic);
                     pictureHolder.invalidate();
                 }
             }
             else if (resultCode == Activity.RESULT_CANCELED) {...}
    }

And there you go! 你去吧!

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM