Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

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 に特定の文字列が含まれている等の条件でそれ経由を判別させて処理させる

hahirusan
!Gâi tsēs
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away