4
誰もこのコードで何が起こっているのかをより良く理解するために、このコードをコメントアウトできますか?キャッシングビットマップコードが混乱する
ありがとうございました。
fis = new FileInputStream(cacheFile);
Bitmap local = BitmapFactory.decodeStream(fis);
誰もこのコードで何が起こっているのかをより良く理解するために、このコードをコメントアウトできますか?キャッシングビットマップコードが混乱する
ありがとうございました。
fis = new FileInputStream(cacheFile);
Bitmap local = BitmapFactory.decodeStream(fis);
/**
* Write bitmap associated with a url to disk cache
*/
private void putBitmapInDiskCache(Uri url, Bitmap avatar) {
// Create a path pointing to the system-recommended cache dir for the app, with sub-dir named
// thumbnails
File cacheDir = new File(context.getCacheDir(), "thumbnails");
// Create a path in that dir for a file, named by the default hash of the url
File cacheFile = new File(cacheDir, ""+url.hashCode());
try {
// Create a file at the file path, and open it for writing obtaining the output stream
cacheFile.createNewFile();
FileOutputStream fos = new FileOutputStream(cacheFile);
// Write the bitmap to the output stream (and thus the file) in PNG format (lossless compression)
avatar.compress(CompressFormat.PNG, 100, fos);
// Flush and close the output stream
fos.flush();
fos.close();
} catch (Exception e) {
// Log anything that might go wrong with IO to file
Log.e(LOG_TAG, "Error when saving image to cache. ", e);
}
}
第二部分:
// Open input stream to the cache file
fis = new FileInputStream(cacheFile);
// Read a bitmap from the file (which presumable contains bitmap in PNG format, since
// that's how files are created)
Bitmap local = BitmapFactory.decodeStream(fis);
おかげで、それは似てそれらを読むために
!あなたは最後の部分を逃した。ファイルの読み取りについて –
2番目の部分を含めるように更新しました – antlersoft
2番目の部分では、CachFile部分には何が入りますか?どのように私はcacheFileの名前が分かっていますか? –