我正在尝试在 android 上捕获图像并将其显示在图像视图上;活动开始时调用的捕获意图,当我运行应用程序时,图像视图与调用捕获意图的活动相同,相机捕获图像两次,然后在图像视图中显示图像?!任何想法为什么?我该如何解决?
> 活动.java
public class View extends Activity{
ImageView imgview;
Bitmap Bmp;
final static int cameraData = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.camera);
imgview = (ImageView) findViewById(R.id.imgview);
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, cameraData);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bmp = (Bitmap) extras.get("data");
imgview.setImageBitmap(Bmp); }
}}
> 相机.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:opencv="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="@+id/imgview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="Image view"
android:src="@drawable/ic_launcher"
/>
</FrameLayout>