我试图在本地保存图像,但是当我使用设备资源管理器并导航到NewVisionARDirectory
时。我似乎看不到它。这是保存的/data/user/0/com.xxx.xxxx/app_NewVisionARDirectory
我正在使用Picasso将下载的图像从URL更改为Bitmap
。
以下是我用于在设备上本地保存URL图像的代码:
try {
@SuppressLint("DefaultLocale") String fileName = String.format("%d.jpg", System.currentTimeMillis());
FileOutputStream fos = null;
try {
Bitmap bitmap = Picasso.get().load(MyUrl).get();
//Saving the Image Internally.
ContextWrapper cw = new ContextWrapper(context);
// path to /data/data/yourapp/app_data/imageDir
File directory = cw.getDir("NewVisionARDirectory", Context.MODE_PRIVATE);
Toast.makeText(context, "" + directory, Toast.LENGTH_LONG).show();
File mypath = new File(directory, fileName);
fos = new FileOutputStream(mypath);
// Use the compress method on the BitMap object to write image to the OutputStream
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
System.out.println("----- Bitmap path -- " + bitmap);
fos.flush();
fos.close();
Toast.makeText(context, "Seems working ....", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(context, "Something wrong" + e, Toast.LENGTH_LONG).show();
} finally {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(context, "Something wrong" + e, Toast.LENGTH_LONG).show();
}
}
} catch (Exception e) {
}
return null;
}