使用Android中的摄像头活动 [英] Using the camera activity in Android
问题描述
如果你想使用内置的,它使用了原生的Android摄像头摄像头的活动,只要做到以下几点。
If you want to use the built-in camera activity which uses the native Android camera, simply do the following.
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?
推荐答案
如果你想获得的图像放回盛开,传递的URI EXTRA_OUTPUT额外内的意向。如果你没事了短小的位图(你应该是),只需要调用的意图是正常的。
If you want to get the image back in its full glory, pass in a uri to the Intent within the EXTRA_OUTPUT extra. If you're fine with a smallish bitmap (and you should be), just call the intent as normal.
现在你有两个选择,处理图像在EXTRA_OUTPUT额外返回的URI,或做你onActivityResult方法如下:
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:
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) {...}
}
和你去那里!
这篇关于使用Android中的摄像头活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!