0

我正在使用 LazyList 代码加载我的外部图像,没有问题。我创建了一个不需要连接的应用程序的“虚拟”版本,因此我将所有文件都放在本地。如何调整此代码以获取存储在我的可绘制文件夹中的本地图像而不是 http url?

imageLoader.DisplayImage(urls[position], mContext, vidImg_iv);

public void DisplayImage(String url, Context context, ImageView imageView)
    {
        imageViews.put(imageView, url);
        Bitmap bitmap=memoryCache.get(url);
        if(bitmap!=null) {
            imageView.setImageBitmap(bitmap);
        } else {
            queuePhoto(url, context, imageView);
            imageView.setImageResource(stub_id);
        }    
    }

如果我不使用下面的 ImageLoader 类,我的内存就会用完:

if (urls[position].contains("1612802193_1625181163001_20120507051900-national")) {
                vidImg_iv.setImageResource(R.drawable.national_still);
            }
            else if (urls[position].toString().contains("1612802193_1625188510001_20120507050000-sports")) {
                vidImg_iv.setImageResource(R.drawable.sports_still);
            }
            else if (urls[position].toString().contains("1612802193_1625189005001_20120507050000-national-sp")) {
                vidImg_iv.setImageResource(R.drawable.national_spanish_still);
            }
            else if (urls[position].contains("1612802193_1625255029001_20120507080000-snap")) {
                vidImg_iv.setImageResource(R.drawable.snap_still);
            }
            else if (urls[position].contains("1612802193_1625256948001_20120507075800-breaking")) {
                vidImg_iv.setImageResource(R.drawable.breaking_still);
            }
            else if (urls[position].contains("1612802193_1625308288001_20120507080800-vbmarguh")) {
                vidImg_iv.setImageResource(R.drawable.vbmarguh_still);
            }
            else if (urls[position].contains("1612802193_1625308309001_20120507083200-extreme")) {
                vidImg_iv.setImageResource(R.drawable.extreme_still);
            }
            else if (urls[position].contains("1612802193_1625188512001_20120507050000-sports")) {
                vidImg_iv.setImageResource(R.drawable.sports_still);
            }
4

1 回答 1

0
//Load a bitmap from local resources
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.some_image);
imageView.setImageBitmap(bitmap);

//Load an image from the assets folder
AssetManager assetManager = context.getAssets();
BufferedInputStream buf = new BufferedInputStream(assetManager.open("filename"));
Bitmap bitmap = BitmapFactory.decodeStream(buf);
buf.close();
imageView.setImageBitmap(bitmap);
于 2012-05-08T17:00:38.837 回答