我将位图存储在 SD 卡中,同时检索失去它们的质量。我该如何解决这个问题。下面是我将位图存储在 SD 卡中的代码。
public void saveExternalPrivateStorage(File folderDir, String fname,
Bitmap bitmap) {
File file = new File(folderDir, fname);
if (file.exists()) {
file.delete();
}
if ((folderDir.mkdirs() || folderDir.isDirectory())) {
try {
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 0, out);
out.flush();
out.close();
System.out.println("Stored");
System.out.println(file.getAbsolutePath());
System.out.println("Stored");
} catch (Exception e) {
e.printStackTrace();
}
}
}
调用此方法:
File folderDir= new File(getActivity().getExternalFilesDir("myfolder"),"/images");
storeImagesIndevices.saveExternalPrivateStorage(folderDir,filename,imgBitmapUrls.get(i));
从 SD 卡中检索:
Bitmap bitmap2 = BitmapFactory.decodeFile(folderDir+"/"+data.getTid());
dbimgBitmapUrls.put(data.get_tid()-1, bitmap2);