0

我正在使用由 Koushik Dutta (Koush) 开发的 UrlImageViewHelper 库。这是我正在做的

  1. 将图像从 url 加载到位于 gridview 内的 imageview 中。
  2. 图像加载工作完美,速度非常快。

我正在尝试将加载在 imageview 中的图像保存为墙纸,但它崩溃并引发了投射异常。

编码

UrlViewImageHelper.setURLDrawable(imageView,"some url here");
Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();

上面的行抛出了这个异常

02-26 06:54:07.987: E/AndroidRuntime(19659): java.lang.ClassCastException: com.koushikdutta.urlimageviewhelper.UrlImageViewHelper$ZombieDrawable

如何将 imageView 中的图像作为位图获取?我究竟做错了什么?

我知道我可以使用其他一些库,例如 Android Universal Image Loader(尚未尝试过)、SmartImageView(好但慢),但 koush 的库非常快速且易于使用。

4

1 回答 1

0

URLViewImageHelper downloads the image in separate thread asynchronously, hence at the point you call imageView.getDrawable(), the image not loaded yet.

What u can try is to register a callback object to be notified when image finished loading:

UrlViewImageHelper.setURLDrawable(imageView,url, defaultResource, new UrlImageViewCallback() {
    @Override
    public void onLoaded(ImageView imageView, Bitmap loadedBitmap, String url, boolean loadedFromCache) {
        // your method here
        Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();

    }
}) ;
于 2013-03-18T07:05:18.623 回答