How to get image from sdcard in android?(如何从android中的sdcard获取图像?)
问题描述
我想创建一个简单的应用程序,我想从 sdcard 获取图像但不能成功.我的代码在下面
i want create simple app in which i want get the image from sdcard but can`t success. my code is below
File myFile = new File("/sdcard/photo.jpg");
ImageView jpgView = (ImageView)findViewById(R.id.imageView);
BitmapDrawable d = new BitmapDrawable(getResources(), myFile.getAbsolutePath());
jpgView.setImageDrawable(d);
但无法获取图像.
推荐答案
使用下面的代码代替你的代码.
Use below code instead of your code.
File f = new File("/mnt/sdcard/photo.jpg");
ImageView mImgView1 = (ImageView)findViewById(R.id.imageView);
Bitmap bmp = BitmapFactory.decodeFile(f.getAbsolutePath());
mImgView1.setImageBitmap(bmp);
这篇关于如何从android中的sdcard获取图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!