gpt4 book ai didi

android - 如何从android中的内存中读取图像?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:54:13 25 4
gpt4 key购买 nike

我已经保存图像的内部存储器的屏幕截图。
我想在 ImageView 中读取图像。那么如何获取图像路径或如何从内存中读取图像?请帮助我..

我尝试了一些代码,但它不起作用:-

 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);

this is my internal memory which i save that image already

最佳答案

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()));
}

Code isn't tested. Or Try Below!

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();
}

}

关于android - 如何从android中的内存中读取图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31154777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com