public ImageDecodingInfo(String imageKey, String imageUri, String originalImageUri, ImageSize targetSize, ViewScaleType viewScaleType, ImageDownloader downloader, DisplayImageOptions displayOptions) { this.imageKey = imageKey; this.imageUri = imageUri; this.originalImageUri = originalImageUri; this.targetSize = targetSize; this.imageScaleType = displayOptions.getImageScaleType(); this.viewScaleType = viewScaleType; this.downloader = downloader; this.extraForDownloader = displayOptions.getExtraForDownloader(); considerExifParams = displayOptions.isConsiderExifParams(); decodingOptions = new Options(); copyOptions(displayOptions.getDecodingOptions(), decodingOptions); }
public static float computeImageScale(ImageSize srcSize, ImageSize targetSize, ViewScaleType viewScaleType, boolean stretch) { int destWidth; int srcWidth = srcSize.getWidth(); int srcHeight = srcSize.getHeight(); int targetWidth = targetSize.getWidth(); int targetHeight = targetSize.getHeight(); float widthScale = ((float) srcWidth) / ((float) targetWidth); float heightScale = ((float) srcHeight) / ((float) targetHeight); int destHeight; if ((viewScaleType != ViewScaleType.FIT_INSIDE || widthScale < heightScale) && (viewScaleType != ViewScaleType.CROP || widthScale >= heightScale)) { destWidth = (int) (((float) srcWidth) / heightScale); destHeight = targetHeight; } else { destWidth = targetWidth; destHeight = (int) (((float) srcHeight) / widthScale); } if ((stretch || destWidth >= srcWidth || destHeight >= srcHeight) && (!stretch || destWidth == srcWidth || destHeight == srcHeight)) { return 1.0f; } return ((float) destWidth) / ((float) srcWidth); }
private boolean resizeAndSaveImage(int maxWidth, int maxHeight) throws IOException { File targetFile = this.configuration.diskCache.get(this.uri); if (targetFile == null || !targetFile.exists()) { return false; } Bitmap bmp = this.decoder.decode(new ImageDecodingInfo(this.memoryCacheKey, Scheme.FILE.wrap(targetFile.getAbsolutePath()), this.uri, new ImageSize(maxWidth, maxHeight), ViewScaleType.FIT_INSIDE, getDownloader(), new Builder().cloneFrom(this.options).imageScaleType(ImageScaleType.IN_SAMPLE_INT).build())); if (!(bmp == null || this.configuration.processorForDiskCache == null)) { L.d(LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISK, this.memoryCacheKey); bmp = this.configuration.processorForDiskCache.process(bmp); if (bmp == null) { L.e(ERROR_PROCESSOR_FOR_DISK_CACHE_NULL, this.memoryCacheKey); } } if (bmp == null) { return false; } boolean saved = this.configuration.diskCache.save(this.uri, bmp); bmp.recycle(); return saved; }
private boolean resizeAndSaveImage(int maxWidth, int maxHeight) throws IOException { File targetFile = this.configuration.diskCache.get(this.uri); if (targetFile == null || !targetFile.exists()) { return false; } Bitmap bmp = this.decoder.decode(new ImageDecodingInfo(this.memoryCacheKey, Scheme.FILE .wrap(targetFile.getAbsolutePath()), this.uri, new ImageSize(maxWidth, maxHeight) , ViewScaleType.FIT_INSIDE, getDownloader(), new Builder().cloneFrom(this .options).imageScaleType(ImageScaleType.IN_SAMPLE_INT).build())); if (!(bmp == null || this.configuration.processorForDiskCache == null)) { L.d(LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISK, this.memoryCacheKey); bmp = this.configuration.processorForDiskCache.process(bmp); if (bmp == null) { L.e(ERROR_PROCESSOR_FOR_DISK_CACHE_NULL, this.memoryCacheKey); } } if (bmp == null) { return false; } boolean saved = this.configuration.diskCache.save(this.uri, bmp); bmp.recycle(); return saved; }
Bitmap tryLoadBitmap(ImageViewAware imageAware) { Bitmap bitmap = null; try { java.io.File imageFile = diskCache.get(getMessage().get_id()); if (imageFile != null && imageFile.exists() && imageFile.length() > 0) { ViewScaleType viewScaleType = imageAware.getScaleType(); ImageSize imageSize = ImageSizeUtils.defineTargetSizeForView(imageAware, new ImageSize(MainApp.CONTEXT.getResources().getDisplayMetrics().widthPixels, MainApp.CONTEXT.getResources().getDisplayMetrics().heightPixels)); ImageDecodingInfo decodingInfo = new ImageDecodingInfo(getMessage().get_id(), ImageDownloader.Scheme.FILE.wrap(imageFile.getAbsolutePath()), getMessage().get_id(), imageSize, viewScaleType, new BaseImageDownloader(MainApp.CONTEXT), options); bitmap = decoder.decode(decodingInfo); MainApp.memoryCache.put(getMessage().get_id(), bitmap); } } catch (Exception ignored) { ignored.printStackTrace(); } return bitmap; }
public void loadImage(String s, ImageSize imagesize, DisplayImageOptions displayimageoptions, ImageLoadingListener imageloadinglistener, ImageLoadingProgressListener imageloadingprogresslistener) { a(); if (imagesize == null) { imagesize = h.a(); } DisplayImageOptions displayimageoptions1; if (displayimageoptions == null) { displayimageoptions1 = h.r; } else { displayimageoptions1 = displayimageoptions; } displayImage(s, new NonViewAware(s, imagesize, ViewScaleType.CROP), displayimageoptions1, imageloadinglistener, imageloadingprogresslistener); }
public NonViewAware(String s, ImageSize imagesize, ViewScaleType viewscaletype) { if (imagesize == null) { throw new IllegalArgumentException("imageSize must not be null"); } if (viewscaletype == null) { throw new IllegalArgumentException("scaleType must not be null"); } else { imageUri = s; imageSize = imagesize; scaleType = viewscaletype; return; } }
public ImageDecodingInfo(String imageKey, String imageUri, ImageSize targetSize, ViewScaleType viewScaleType, ImageDownloader downloader, DisplayImageOptions displayOptions) { this.imageKey = imageKey; this.imageUri = imageUri; this.targetSize = targetSize; this.imageScaleType = displayOptions.getImageScaleType(); this.viewScaleType = viewScaleType; this.downloader = downloader; this.extraForDownloader = displayOptions.getExtraForDownloader(); considerExifParams = displayOptions.isConsiderExifParams(); decodingOptions = new Options(); copyOptions(displayOptions.getDecodingOptions(), decodingOptions); }
/** * Computes scale of target size (<b>targetSize</b>) to source size (<b>srcSize</b>).<br /> * <br /> * <b>Examples:</b><br /> * <p/> * <pre> * srcSize(40x40), targetSize(10x10) -> scale = 0.25 * * srcSize(10x10), targetSize(20x20), stretch = false -> scale = 1 * srcSize(10x10), targetSize(20x20), stretch = true -> scale = 2 * * srcSize(100x100), targetSize(20x40), viewScaleType = FIT_INSIDE -> scale = 0.2 * srcSize(100x100), targetSize(20x40), viewScaleType = CROP -> scale = 0.4 * </pre> * * @param srcSize Source (image) size * @param targetSize Target (view) size * @param viewScaleType {@linkplain ViewScaleType Scale type} for placing image in view * @param stretch Whether source size should be stretched if target size is larger than source size. If <b>false</b> * then result scale value can't be greater than 1. * @return Computed scale */ public static float computeImageScale(ImageSize srcSize, ImageSize targetSize, ViewScaleType viewScaleType, boolean stretch) { final int srcWidth = srcSize.getWidth(); final int srcHeight = srcSize.getHeight(); final int targetWidth = targetSize.getWidth(); final int targetHeight = targetSize.getHeight(); final float widthScale = (float) srcWidth / targetWidth; final float heightScale = (float) srcHeight / targetHeight; final int destWidth; final int destHeight; if ((viewScaleType == ViewScaleType.FIT_INSIDE && widthScale >= heightScale) || (viewScaleType == ViewScaleType.CROP && widthScale < heightScale)) { destWidth = targetWidth; destHeight = (int) (srcHeight / widthScale); } else { destWidth = (int) (srcWidth / heightScale); destHeight = targetHeight; } float scale = 1; if ((!stretch && destWidth < srcWidth && destHeight < srcHeight) || (stretch && destWidth != srcWidth && destHeight != srcHeight)) { scale = (float) destWidth / srcWidth; } return scale; }
/** 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; }
@Override public ViewScaleType getScaleType() { ImageView imageView = (ImageView) viewRef.get(); if (imageView != null) { return ViewScaleType.fromImageView(imageView); } return super.getScaleType(); }
public NonViewAware(String imageUri, ImageSize imageSize, ViewScaleType scaleType) { if (imageSize == null) throw new IllegalArgumentException("imageSize must not be null"); if (scaleType == null) throw new IllegalArgumentException("scaleType must not be null"); this.imageUri = imageUri; this.imageSize = imageSize; this.scaleType = scaleType; }
public static int computeImageSampleSize(ImageSize srcSize, ImageSize targetSize, ViewScaleType viewScaleType, boolean powerOf2Scale) { int srcWidth = srcSize.getWidth(); int srcHeight = srcSize.getHeight(); int targetWidth = targetSize.getWidth(); int targetHeight = targetSize.getHeight(); int scale = 1; int halfWidth; int halfHeight; switch (viewScaleType) { case FIT_INSIDE: if (!powerOf2Scale) { scale = Math.max(srcWidth / targetWidth, srcHeight / targetHeight); break; } halfWidth = srcWidth / 2; halfHeight = srcHeight / 2; while (true) { if (halfWidth / scale <= targetWidth && halfHeight / scale <= targetHeight) { break; } scale *= 2; } break; case CROP: if (!powerOf2Scale) { scale = Math.min(srcWidth / targetWidth, srcHeight / targetHeight); break; } halfWidth = srcWidth / 2; halfHeight = srcHeight / 2; while (halfWidth / scale > targetWidth && halfHeight / scale > targetHeight) { scale *= 2; } break; } if (scale < 1) { scale = 1; } return considerMaxTextureSize(srcWidth, srcHeight, scale, powerOf2Scale); }
public ImageDecodingInfo(String imageKey, String imageUri, String originalImageUri, ImageSize targetSize, ViewScaleType viewScaleType, ImageDownloader downloader, DisplayImageOptions displayOptions) { this.imageKey = imageKey; this.imageUri = imageUri; this.originalImageUri = originalImageUri; this.targetSize = targetSize; this.imageScaleType = displayOptions.getImageScaleType(); this.viewScaleType = viewScaleType; this.downloader = downloader; this.extraForDownloader = displayOptions.getExtraForDownloader(); this.considerExifParams = displayOptions.isConsiderExifParams(); copyOptions(displayOptions.getDecodingOptions(), this.decodingOptions); }
public void loadImage(String uri, ImageSize targetImageSize, DisplayImageOptions options, ImageLoadingListener listener, ImageLoadingProgressListener progressListener) { checkConfiguration(); if (targetImageSize == null) { targetImageSize = this.configuration.getMaxImageSize(); } if (options == null) { options = this.configuration.defaultDisplayImageOptions; } displayImage(uri, new NonViewAware(uri, targetImageSize, ViewScaleType.CROP), options, listener, progressListener); }
public ViewScaleType getScaleType() { ImageView imageView = (ImageView) this.viewRef.get(); if (imageView != null) { return ViewScaleType.fromImageView(imageView); } return super.getScaleType(); }
public NonViewAware(String imageUri, ImageSize imageSize, ViewScaleType scaleType) { if (imageSize == null) { throw new IllegalArgumentException("imageSize must not be null"); } else if (scaleType == null) { throw new IllegalArgumentException("scaleType must not be null"); } else { this.imageUri = imageUri; this.imageSize = imageSize; this.scaleType = scaleType; } }
/** * 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; }