简单调用摄像头

public void startCamera(View view){
Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 1);

}
//用于页面显示
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1 && resultCode == RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
((ImageView) findViewById(R.id.imageView)).setImageBitmap(photo);// 将图片显示在ImageView里
}

}
}

//布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<Button
android:id="@+id/ss"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="camera"/>
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="250dp" />
</LinearLayout>

posted on 2019-11-23 09:30  带镐伤的土豆  阅读(194)  评论(0编辑  收藏  举报

导航