Search in sources :

Example 1 with ImageSize

use of com.nostra13.universalimageloader.core.assist.ImageSize in project Android-Universal-Image-Loader by nostra13.

the class BaseImageDecoder method prepareDecodingOptions.

protected Options prepareDecodingOptions(ImageSize imageSize, ImageDecodingInfo decodingInfo) {
    ImageScaleType scaleType = decodingInfo.getImageScaleType();
    int scale;
    if (scaleType == ImageScaleType.NONE) {
        scale = 1;
    } else if (scaleType == ImageScaleType.NONE_SAFE) {
        scale = ImageSizeUtils.computeMinImageSampleSize(imageSize);
    } else {
        ImageSize targetSize = decodingInfo.getTargetSize();
        boolean powerOf2 = scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2;
        scale = ImageSizeUtils.computeImageSampleSize(imageSize, targetSize, decodingInfo.getViewScaleType(), powerOf2);
    }
    if (scale > 1 && loggingEnabled) {
        L.d(LOG_SUBSAMPLE_IMAGE, imageSize, imageSize.scaleDown(scale), scale, decodingInfo.getImageKey());
    }
    Options decodingOptions = decodingInfo.getDecodingOptions();
    decodingOptions.inSampleSize = scale;
    return decodingOptions;
}
Also used : ImageScaleType(com.nostra13.universalimageloader.core.assist.ImageScaleType) Options(android.graphics.BitmapFactory.Options) ImageSize(com.nostra13.universalimageloader.core.assist.ImageSize)

Example 2 with ImageSize

use of com.nostra13.universalimageloader.core.assist.ImageSize in project Android-Universal-Image-Loader by nostra13.

the class LoadAndDisplayImageTask method resizeAndSaveImage.

/**
 * Decodes image file into Bitmap, resize it and save it back
 */
private boolean resizeAndSaveImage(int maxWidth, int maxHeight) throws IOException {
    // Decode image file, compress and re-save it
    boolean saved = false;
    File targetFile = configuration.diskCache.get(uri);
    if (targetFile != null && targetFile.exists()) {
        ImageSize targetImageSize = new ImageSize(maxWidth, maxHeight);
        DisplayImageOptions specialOptions = new DisplayImageOptions.Builder().cloneFrom(options).imageScaleType(ImageScaleType.IN_SAMPLE_INT).build();
        ImageDecodingInfo decodingInfo = new ImageDecodingInfo(memoryCacheKey, Scheme.FILE.wrap(targetFile.getAbsolutePath()), uri, targetImageSize, ViewScaleType.FIT_INSIDE, getDownloader(), specialOptions);
        Bitmap bmp = decoder.decode(decodingInfo);
        if (bmp != null && configuration.processorForDiskCache != null) {
            L.d(LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISK, memoryCacheKey);
            bmp = configuration.processorForDiskCache.process(bmp);
            if (bmp == null) {
                L.e(ERROR_PROCESSOR_FOR_DISK_CACHE_NULL, memoryCacheKey);
            }
        }
        if (bmp != null) {
            saved = configuration.diskCache.save(uri, bmp);
            bmp.recycle();
        }
    }
    return saved;
}
Also used : Bitmap(android.graphics.Bitmap) ImageSize(com.nostra13.universalimageloader.core.assist.ImageSize) ImageDecodingInfo(com.nostra13.universalimageloader.core.decode.ImageDecodingInfo) File(java.io.File)

Example 3 with ImageSize

use of com.nostra13.universalimageloader.core.assist.ImageSize in project BlogSource by TeachCourse.

the class DownloadImgAPI method setImageViewSize.

/**
 * 指定加载图片的大小
 *
 * @param imageView
 * @param url
 */
public static void setImageViewSize(final ImageView imageView, String url) {
    ImageSize targetSize = new ImageSize(80, 50);
    App.getApplication().getImageLoader().loadImage(url, targetSize, options, new SimpleImageLoadingListener() {

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            imageView.setImageBitmap(loadedImage);
        }
    });
}
Also used : SimpleImageLoadingListener(com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener) Bitmap(android.graphics.Bitmap) ImageSize(com.nostra13.universalimageloader.core.assist.ImageSize) ImageView(android.widget.ImageView) View(android.view.View)

Example 4 with ImageSize

use of com.nostra13.universalimageloader.core.assist.ImageSize in project Memento-Calendar by alexstyl.

the class UILImageLoader method load.

@Override
public Request load(final URI imagePath) {
    final DisplayImageOptions.Builder builder = standardBuilder();
    return new Request() {

        @Override
        public void into(ImageView imageView) {
            uil.displayImage(imagePath.toString(), imageView, builder.build());
        }

        @Override
        public Request asCircle() {
            builder.displayer(defaultCircleDisplayer);
            return this;
        }

        @Override
        public FixedSizeRequest withSize(@Px final int width, @Px final int height) {
            builder.displayer(DefaultConfigurationFactory.createBitmapDisplayer());
            return new FixedSizeRequest() {

                @Override
                public Optional<Bitmap> synchronously() {
                    Bitmap bitmap = uil.loadImageSync(imagePath.toString(), new ImageSize(width, height), builder.build());
                    if (bitmap == null) {
                        return Optional.absent();
                    } else {
                        return new Optional<>(bitmap);
                    }
                }

                @Override
                public void into(final ImageLoadedConsumer consumer) {
                    builder.displayer(DefaultConfigurationFactory.createBitmapDisplayer());
                    uil.loadImage(imagePath.toString(), builder.build(), new SimpleImageLoadingListener() {

                        @Override
                        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                            consumer.onImageLoaded(loadedImage);
                        }

                        @Override
                        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                            consumer.onLoadingFailed();
                        }
                    });
                }
            };
        }
    };
}
Also used : Optional(com.alexstyl.specialdates.Optional) ImageSize(com.nostra13.universalimageloader.core.assist.ImageSize) Px(android.support.annotation.Px) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) ImageView(android.widget.ImageView) View(android.view.View) SimpleImageLoadingListener(com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener) Bitmap(android.graphics.Bitmap) ImageView(android.widget.ImageView) DisplayImageOptions(com.nostra13.universalimageloader.core.DisplayImageOptions)

Example 5 with ImageSize

use of com.nostra13.universalimageloader.core.assist.ImageSize in project LibreraReader by foobnix.

the class ImageLoaderConfiguration method getMaxImageSize.

ImageSize getMaxImageSize() {
    DisplayMetrics displayMetrics = resources.getDisplayMetrics();
    int width = maxImageWidthForMemoryCache;
    if (width <= 0) {
        width = displayMetrics.widthPixels;
    }
    int height = maxImageHeightForMemoryCache;
    if (height <= 0) {
        height = displayMetrics.heightPixels;
    }
    return new ImageSize(width, height);
}
Also used : ImageSize(com.nostra13.universalimageloader.core.assist.ImageSize) DisplayMetrics(android.util.DisplayMetrics)

Aggregations

ImageSize (com.nostra13.universalimageloader.core.assist.ImageSize)20 Bitmap (android.graphics.Bitmap)11 View (android.view.View)5 Options (android.graphics.BitmapFactory.Options)4 ImageScaleType (com.nostra13.universalimageloader.core.assist.ImageScaleType)4 File (java.io.File)4 ImageView (android.widget.ImageView)3 SimpleImageLoadingListener (com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener)3 Matrix (android.graphics.Matrix)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 DisplayMetrics (android.util.DisplayMetrics)2 RemoteViews (android.widget.RemoteViews)2 DisplayImageOptions (com.nostra13.universalimageloader.core.DisplayImageOptions)2 FailReason (com.nostra13.universalimageloader.core.assist.FailReason)2 ImageDecodingInfo (com.nostra13.universalimageloader.core.decode.ImageDecodingInfo)2 NonViewAware (com.nostra13.universalimageloader.core.imageaware.NonViewAware)2 Intent (android.content.Intent)1 Canvas (android.graphics.Canvas)1 Point (android.graphics.Point)1 Drawable (android.graphics.drawable.Drawable)1