public static void setBitmapToDiskLruCache(DiskLruCache diskLruCache, String key, Bitmap bitmap) throws IOException { DiskLruCache.Editor editor = diskLruCache.edit(key); OutputStream outputStream = editor.newOutputStream(0); bitmap.compress(Bitmap.CompressFormat.WEBP, 100, outputStream); outputStream.close(); editor.commit(); diskLruCache.flush(); }
public static Bitmap getBitmapFromDiskLurCache(DiskLruCache diskLruCache, String key) throws IOException { DiskLruCache.Snapshot snapshot = diskLruCache.get(key); if (snapshot == null) return null; InputStream inputStream = snapshot.getInputStream(0); return BitmapFactory.decodeStream(inputStream); }