Exemplo n.º 1
0
 private Bitmap decodeImage(String imageUri) throws IOException {
   ViewScaleType viewScaleType = imageAware.getScaleType();
   ImageDecodingInfo decodingInfo =
       new ImageDecodingInfo(
           memoryCacheKey, imageUri, targetSize, viewScaleType, getDownloader(), options);
   return decoder.decode(decodingInfo);
 }
Exemplo n.º 2
0
 /** Decodes image file into Bitmap, resize it and save it back */
 private boolean resizeAndSaveImage(File targetFile, int maxWidth, int maxHeight)
     throws IOException {
   // Decode image file, compress and re-save it
   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()),
           targetImageSize,
           ViewScaleType.FIT_INSIDE,
           getDownloader(),
           specialOptions);
   Bitmap bmp = decoder.decode(decodingInfo);
   if (bmp != null && configuration.processorForDiscCache != null) {
     log(LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISC);
     bmp = configuration.processorForDiscCache.process(bmp);
     if (bmp == null) {
       L.e(ERROR_PROCESSOR_FOR_DISC_CACHE_NULL, memoryCacheKey);
     }
   }
   if (bmp != null) {
     OutputStream os = new BufferedOutputStream(new FileOutputStream(targetFile), BUFFER_SIZE);
     try {
       bmp.compress(
           configuration.imageCompressFormatForDiscCache,
           configuration.imageQualityForDiscCache,
           os);
     } finally {
       IoUtils.closeSilently(os);
     }
     bmp.recycle();
   }
   return true;
 }