[英]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.