此内存存储器的屏幕截图已保存图像。
我想在图像视图中读取图像。那么如何获取图像路径或如何从内存中读取图像?
请帮帮我..
我尝试了一些代码,但它不起作用: -
FileInputStream fis;
String filePath = activity.getFilesDir().getPath();
String path = data.get(position).get("product_image");
fis = openFileInput(filePath+"/broccolicasserole.jpg");
Bitmap bitmapA = BitmapFactory.decodeStream(fis);
producticon.setImageBitmap(bitmapA);
图像名称来自数据库,如:-data.get(position).get(“product_image”);
也尝试这个代码: -
> String filePath = activity.getFilesDir().getPath();
File filePath1 = imageLoader.DisplayImage(filePath+data.get(position).get("product_image"), producticon);
答案 0 :(得分:4)
private String readFileFromInternalStorage(){
ImageView imageView = (ImageView) findViewById(R.id.image);
ContextWrapper cw = new ContextWrapper(context);
//path to /data/data/yourapp/app_data/dirName
File directory = cw.getDir("dirName", Context.MODE_PRIVATE);
File mypath=new File(directory,"imagename.jpg");
ImageView imageView = (ImageView) findViewById(R.id.image);
imageView.setImageDrawable(Drawable.createFromPath(mypath.toString()));
}
代码未经过测试。或者试试下面!
private void setImage(String imgPath)
{
try {
File f=new File(imgPath, "imgName.jpg");
Bitmap b = BitmapFactory.decodeStream(new FileInputStream(f));
ImageView img=(ImageView)findViewById(R.id.image);
img.setImageBitmap(b);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
答案 1 :(得分:1)
尝试这样就可以了,
ImageView picture = (ImageView) findViewById(R.id.imageView1);
String pic = result.getString(YourImagepathname);//get path of your image
Bitmap yourSelectedImage1 = BitmapFactory.decodeFile(pic);
picture.setImageBitmap(yourSelectedImage1);