這是緩存圖像文件的代碼。
protected static Map<String, Drawable> cacheThumbs = new HashMap<String, Drawable>();
//代碼緩存圖片
if(thumbUri.length() == 0)
return;
Drawable d = cacheThumbs.get(thumbUri);
if(d == null)
{
String fileName = movie.getId()+"_"+thumbUri.substring(thumbUri.lastIndexOf('/')+1);
cacheFile = new File(application.getCacheDir(), fileName);
if(!cacheFile.exists())
{
//Log.v(LOG_TAG,"Fetching "+thumbUri +" and caching in "+cacheFile.getAbsolutePath());
InputStream bis = (InputStream) new URL(thumbUri).getContent();
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(cacheFile));
int read = 0;
while((read = bis.read(buffer)) != -1)
bos.write(buffer, 0, read);
bis.close();
bos.close();
Log.v(LOG_TAG,thumbUri + " fetched");
}//if
Log.v(LOG_TAG,thumbUri + " in cache");
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(cacheFile), 9000);
d = Drawable.createFromStream(bis, "src name");
bis.close();
cacheThumbs.put(thumbUri, d);
問候, 斯特凡
什麼是圖像分辨率? – MobileCushion