Android 照相机照片图像全尺寸图像视图

Android 照相机照片图像全尺寸图像视图,android,android-layout,Android,Android Layout,我有一个带按钮的视图和一个imageview。在那里,我想用android相机拍摄一张大尺寸的照片,并将其设置在imageview中。使用下面的代码,我在imageview中没有得到任何图像。我的代码出了什么问题?请帮忙。谢谢你的帮助 package de.camera.test; ... public class CameratestActivity extends Activity implements OnClickListener { /** Called when the activ

我有一个带按钮的视图和一个imageview。在那里,我想用android相机拍摄一张大尺寸的照片,并将其设置在imageview中。使用下面的代码,我在imageview中没有得到任何图像。我的代码出了什么问题?请帮忙。谢谢你的帮助

package de.camera.test;
...

public class CameratestActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */

public File mTemp;
public ImageView image;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button cameraButton = (Button) findViewById(R.id.button);
    image = (ImageView) findViewById(R.id.imageview);
    cameraButton.setOnClickListener(this);
}

public void onClick(View v) {

    Intent camera = new Intent(
            android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

    try {
        mTemp = File.createTempFile("myCameraShot", null);
        camera.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
                Uri.fromFile(mTemp));
        startActivityForResult(camera, 0);
    } catch (IOException e) {
        e.printStackTrace();
    }

}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (data == null)
        return;
    Bitmap b;
    try {
        b = Media.getBitmap(getContentResolver(), Uri.fromFile(mTemp));

        image.setImageBitmap(b);
        Drawable d = image.getDrawable();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
}
Layout main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

<ImageView
    android:id="@+id/imageview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />


</LinearLayout>

文件.createTempFile(“myCameraShot”,null)的文档说明在临时文件的默认位置创建临时文件。此文件很有可能受到保护,只有您的应用程序才能访问它

我认为您可以尝试指定SD卡上的文件路径

我还建议你看看这个: