【发布时间】:2014-09-11 07:56:49
【问题描述】:
我需要一些示例代码来显示相机而不拍照。 最简单的方法是什么?
【问题讨论】:
我需要一些示例代码来显示相机而不拍照。 最简单的方法是什么?
【问题讨论】:
在您的 AndroidManifest.xml 中:
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" />
在您的代码中:
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
【讨论】:
使用此代码作为示例:打开相机
public void open(){
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
捕获图像:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
Bitmap bp = (Bitmap) data.getExtras().get("data");
imgFavorite.setImageBitmap(bp);
}
在 Manifest 中添加权限:
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" />
XML:
内部相对布局采用 Imageview 和 textview
试试这个。
【讨论】:
此链接将比我更好地解释所有内容:http://developer.android.com/guide/topics/media/camera.html
【讨论】:
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
【讨论】: