1
我想写和读一个位图,其他主题上的建议关于这一点,事情是我从来没有得到位图,当我尝试读取保存图像的路径:读取和写入位图android失败
所以我有这样写的位图:
private String saveToInternalStorage(Bitmap bitmapImage){
ContextWrapper cw = new ContextWrapper(getApplicationContext());
// path to /data/data/yourapp/app_data/imageDir
File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
// Create imageDir
File mypath=new File(directory,"captured");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(mypath);
// Use the compress method on the BitMap object to write image to the OutputStream
bitmapImage.compress(Bitmap.CompressFormat.JPEG, 100, fos);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return directory.getAbsolutePath();
}
}
我将返回的路径到另一个活动,然后我把它作为参数来获得这样的位图:
private void loadImageFromStorage(String path)
{
try {
File f=new File(path, "captured.jpg");
Log.d("filehe",f.toString());
b = BitmapFactory.decodeStream(new FileInputStream(f));
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
我觉得我在这里做错了事,但无法弄清楚什么,B变量没有价值:/。
任何帮助?
感谢
我使用毕加索,我只需要对位图传递到其他活动中的我如何使用它的日在目的? – afcosta007
@ afcosta007:“我正在使用毕加索” - 您没有在第二种方法中使用它。 “我怎么用它来达到这个目的?” - 你用一些东西来加载毕加索的图像,比如URL或Uri。将其传递给第二项活动,并让它使用毕加索。 [毕加索将尽可能使用缓存的位图](https://futurestud.io/tutorials/picasso-influencing-image-caching)。 – CommonsWare
所以你说,是我可以使用毕加索从第一种方法给定的路径加载位图? – afcosta007