繁体   English   中英

在Android中使用相机活动

[英]Using the camera activity in Android

如果您想使用使用原生Android相机的内置相机活动,只需执行以下操作即可。

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

你想从你展示的漂亮相机中取回图像 - 但是如何?

如果你想让图像恢复光彩,请将uri传递给EXTRA_OUTPUT额外的Intent。 如果你对一个小的位图很好(你应该这样),只需正常调用意图。

现在您有两个选项,处理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) {...}
    }

你去吧!

暂无
暂无

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

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