如果您想使用使用本机 Android 相机的内置相机 Activity,只需执行以下操作即可。
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
this.startActivityForResult(camera, PICTURE_RESULT);
您想从您展示的漂亮相机中取回图像 - 但如何呢?
如果您想让图像恢复其全部荣耀,请将 uri 传递给 EXTRA_OUTPUT extra 中的 Intent。如果您可以接受较小的位图(您应该如此),只需像平常一样调用意图即可。
现在您有两个选择,处理 EXTRA_OUTPUT extra 中返回的图像的 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) {...}
}
就这样吧!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)