static public Bitmap getAlbumArtFromCache(String artist, String album, Context c)
{
Bitmap artwork = null;
File dirfile = new File(SourceListOperations.getAlbumArtPath(c));
dirfile.mkdirs();
String artfilepath = SourceListOperations.getAlbumArtPath(c) + File.separator + SourceListOperations.makeFilename(artist) + "_" + SourceListOperations.makeFilename(album) + ".png";
File infile = new File(artfilepath);
try
{
artwork = BitmapFactory.decodeFile(infile.getAbsolutePath());
}catch(Exception e){}
if(artwork == null)
{
try
{
artwork = BitmapFactory.decodeResource(c.getResources(), R.drawable.icon);
}catch(Exception ex){}
}
return artwork;
}
有没有什么方法可以限制生成的 Bitmap 对象的大小,比如说,256x256呢?缩略图只需要这么大,我可以创建一个重复函数或者传递一个参数来获取全尺寸的艺术作品以在全屏中显示。
另外,我将这些位图显示在小的 ImageView 上,大约是150x150到200x200。较小的图像比大的图像更容易缩小。有没有办法应用下采样滤镜以平滑图像(例如抗锯齿)?如果不必要,我不想缓存大量额外的缩略图文件,因为这会使管理艺术作品图像变得更加困难(目前您只需将新图像放入目录中,它们就会在下次加载时自动使用)。
完整代码在http://github.org/CalcProgrammer1/CalcTunes,在 src/com/calcprogrammer1/calctunes/AlbumArtManager.java 中,尽管在其他函数中也没什么不同(如果图像丢失则回退到最后.fm检查)。