如何显示画面的ImageView照片中的android采取相机 [英] How to display picture in imageview photo taken by camera in android
本文介绍了如何显示画面的ImageView照片中的android采取相机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人可以告诉如何显示画面的ImageView合影留念通过前置摄像头的安卓有谁能够提供code
can anybody tell How to display picture in imageview photo taken by using front camera in android can anybody provide code
感谢
推荐答案
这里是code试试吧
这是我的xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/linear">
<Button android:id="@+id/btn" android:layout_width="200dp"
android:layout_height="wrap_content" android:text="Click" />
<ImageView android:id="@+id/img_preview"
android:layout_width="fill_parent" android:layout_height="fill_parent" />
</LinearLayout>
下面是活动code
Button btn;
int CAMERA_PIC_REQUEST = 0;
ImageView imgView;
imgView = (ImageView) findViewById(R.id.img_preview);
btn = (Button) findViewById(R.id.btn);
btn.setCompoundDrawables(null, getResources().getDrawable(R.drawable.icon), null, null);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent camera_intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(camera_intent, CAMERA_PIC_REQUEST);
}
});
这里是onActivityResult
here is the onActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode){
case CAMERA_PIC_REQUEST:
if(resultCode==RESULT_OK){
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
imgView.setImageBitmap(thumbnail);
}
}
}
这篇关于如何显示画面的ImageView照片中的android采取相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文