用隐式请求调用系统相机,并且把拍照的相片显示在当前界面

在当前界面的oncreate方法中初始化mbutton、mimageview

然后重写mbutton的点击事件(setOnClickListener):

隐式请求打开相机的代码:

new ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_CODE);

 

然后就可以通过:

Bitmap mbitmap=(Bitmap) data.getExtras().get("data");
代码获取相机拍到的照片

然后把照片通过:

 

mimageView.setImageBitmap(mbitmap);
传给当前界面布局文件的mimageview进行显示

下面是布局文件的代码:

 

<Button
android:id="@+id/b1"
android:text="打开摄像头"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

/>
<ImageView
android:id="@+id/img1"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

 

posted @ 2016-04-21 20:28  IT神文  阅读(517)  评论(0)    收藏  举报