2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UniversalImageLoader で用意されているリソース取得外から画像を取得する

Posted at

UILでは Web, SD card, content provider, assets, drawables (non-9patch images) から画像を取得が用意されているが、例えば API から画像を Base64 でとってきて表示させるにはどうするか

ImageLoaderConfiguration.imageDownloader に用意した ImageLoader をセットすればよさそう

ImageLoaderDisplay.java
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
            ...
            .imageDownloader(new CustomImageLoader(context))
            .build();
ImageLoader.getInstance().init(config);

ImageLoader.getInstance()
                 .displayImage(imageUri,
                            imageView, options);
CustomImageLoader.java
public class CustomImageLoader extends BaseImageDownloader{
    public CustomImageLoader(Context context) {
        super(context);
    }

    @Override
    public InputStream getStream(String imageUri, Object extra) throws IOException {
        if (...)) {
            return imageLoader(imageUri, extra);
        } else return super.getStream(imageUri, extra);
    }

getStream をオーバーライドして、例えば imageUri に特定の文字列が含まれている等の条件でそれ経由を判別させて処理させる

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?