【发布时间】:2017-12-04 11:19:32
【问题描述】:
我正在尝试按照其他主题的建议来编写和读取位图,问题是当我尝试在保存图像的路径上读取时,我永远不会得到位图:
所以我有这个来写位图:
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 variavel 没有价值:/。
有什么帮助吗?
谢谢
【问题讨论】:
标签: java android file bitmap android-file