【问题标题】:Android Universal Image Loader AutoResizeAndroid 通用图像加载器自动调整大小
【发布时间】:2014-06-27 11:57:06
【问题描述】:

这个库允许从网络上自动下载和调整图像大小。 这是网站wiki中代码的sn-p:

    ImageSize targetSize = new ImageSize(120, 80); // result Bitmap will be fit to this size
    imageLoader.loadImage(imageUri, targetSize, displayOptions, new SimpleImageLoadingListener() {
    @Override
    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
        // Do whatever you want with Bitmap
    }
});

这是我的代码:

ImageView imageView = (ImageView)findViewById(R.id.imageGrid1); // view, where the image will be displayed
String imageUrl = "http://img33.imageshack.us/img33/9336/51863504.jpg"; 
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(this));
ImageSize targetSize = new ImageSize(120, 80);
DisplayImageOptions options;

imageLoader.loadImage(imageUrl,  targetSize, options, new SimpleImageLoadingListener() {
    @Override
    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
        // Do whatever you want with Bitmap
    }
});

Eclipse 不想编译返回此错误的代码。 在 imageloader.loadImage 上,错误是

Multiple markers at this line
    - SimpleImageLoadingListener cannot be resolved to a type
    - The method loadImage(String, ImageSize, DisplayImageOptions, ImageLoadingListener) in the type ImageLoader is not applicable for the arguments 
     (String, ImageSize, DisplayImageOptions, new SimpleImageLoadingListener(){})

OnloadingComplete 上的错误是

The method onLoadingComplete(String, View, Bitmap) of type new SimpleImageLoadingListener(){} must override or implement a supertype method

建议?

【问题讨论】:

  • DisplayImageOptions 必须初始化,至少为 null。解决了。​​

标签: android universal-image-loader


【解决方案1】:
ptions = new DisplayImageOptions.Builder()
            .showImageOnLoading(R.drawable.ic_stub)
            .showImageForEmptyUri(R.drawable.ic_empty)
            .showImageOnFail(R.drawable.ic_error).cacheInMemory(true)
            .cacheOnDisk(true).considerExifParams(true)
            .displayer(new RoundedBitmapDisplayer (20))
            .bitmapConfig(Bitmap.Config.RGB_565).build();

【讨论】:

    猜你喜欢
    • 2014-08-15
    • 2014-04-21
    • 1970-01-01
    • 2017-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    相关资源
    最近更新 更多