当我尝试从SD卡上显示图像时,imageview为空
问题描述:
当我尝试从SD卡上显示图像时,imageview为空。有人能帮我吗?当图像存在时,图像视图被设置为空白。 (我有一个JPEG文件Pikachu.jpg
)。当我尝试从SD卡上显示图像时,imageview为空
从Java类:
File image = new File(Environment.getExternalStorageDirectory().getPath()+"/Pikachu.jpg");
if(image.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(image.getAbsolutePath());
ImageView myImage = (ImageView) findViewById(R.id.imageView1);
myImage.setImageBitmap(myBitmap);
Toast.makeText(this,"ok ", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(this,"Error", Toast.LENGTH_SHORT).show();
XML文件:
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="92dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher" />
答
尝试编辑文件构造以下
File image = new File(Environment.getExternalStorageDirectory().toString() + "/Pikachu.jpg");
你为什么不使用myImage.setImageUri(。 ..)? –
如果图像的质量非常高,而且非常大,则不会显示。尝试在清单文件的应用程序标记中设置android:largeHeap =“true”'。 – Rustam
我尝试过使用setimageUri,但它也给了我一个空白图像视图 –