Android 我需要将图像拍摄到ImageView

Android 我需要将图像拍摄到ImageView,android,camera,imageview,Android,Camera,Imageview,我从定制相机拍摄了一张照片,但我无法显示在新活动中拍摄的照片。 这是我的代码,但它不起作用。 怎么了 public class PicturePreview extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activit

我从定制相机拍摄了一张照片,但我无法显示在新活动中拍摄的照片。 这是我的代码,但它不起作用。 怎么了

    public class PicturePreview extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_picture_preview);

    Bundle bundle = getIntent().getExtras();
    String path = bundle.getString("ImagePath");

    ImageView image = (ImageView) findViewById(R.id.photopreview);
    File imgFile = new  File(path);

    if(imgFile.exists()){
        Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
        image.setImageBitmap(myBitmap);

    }


}

}
这是xml文件

<RelativeLayout 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"
tools:context="involved.dreamon.PicturePreview">



<ImageView
    android:id="@+id/photopreview"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:layout_centerInParent="true"/>




</RelativeLayout>

你有什么例外……不清楚。如果没有问题,但不显示图像。然后图像需要压缩以在ImageView中进行设置

有时,当图像调节非常高时,它不显示

使用此方法解决此问题

public Bitmap imageConversion(Bitmap imageBitmap) {
    Bitmap bitmap = imageBitmap;
    float lengthbmp = bitmap.getHeight();
    float widthbmp = bitmap.getWidth();
    if (lengthbmp > 1000) {
        if (widthbmp > 800) {
            bitmap = Bitmap.createScaledBitmap(bitmap, 600, 800, true);
        } else {
            bitmap = Bitmap.createScaledBitmap(bitmap, (int) widthbmp, 800,
                    true);
        }
    }
    return bitmap;
}
用这样的方法

if(imgFile.exists()){
    Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
    image.setImageBitmap(imageConversion(myBitmap));

}

您是否记录映像路径?您是否在图像路径中添加了图像名称?我在CameraActivity ibUse.setOnClickListener(new View.OnClickListener(){public void onClick(View v){String path=“getPath”;//所有内容都已保存,以便我们可以退出应用程序。finish();Intent Intent=new Intent(CameraActivity.this,PicturePreview.class);Bundle extras=new Bundle();extras.putString(“ImagePath”,path);Intent.putExtras(extras);startActivity(Intent);}}}}我不谈论你的听众。我告诉过你记录
stringpath=bundle.getString(“ImagePath”)那,你得到了什么价值。我没有看到任何带有
路径的图像名称
对不起,扎伊杜尔先生,但我是新来的开发人员。。我应该写什么?在哪里?