Exemplo n.º 1
0
 protected Options prepareDecodingOptions(ImageSize imageSize, ImageDecodingInfo decodingInfo) {
   int scale;
   ImageScaleType scaleType = decodingInfo.getImageScaleType();
   if (scaleType == ImageScaleType.NONE) {
     scale = 1;
   } else if (scaleType == ImageScaleType.NONE_SAFE) {
     scale = ImageSizeUtils.computeMinImageSampleSize(imageSize);
   } else {
     boolean powerOf2;
     ImageSize targetSize = decodingInfo.getTargetSize();
     if (scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2) {
       powerOf2 = true;
     } else {
       powerOf2 = false;
     }
     scale =
         ImageSizeUtils.computeImageSampleSize(
             imageSize, targetSize, decodingInfo.getViewScaleType(), powerOf2);
   }
   if (scale > 1 && this.loggingEnabled) {
     C0126L.m33d(
         LOG_SUBSAMPLE_IMAGE,
         imageSize,
         imageSize.scaleDown(scale),
         Integer.valueOf(scale),
         decodingInfo.getImageKey());
   }
   Options decodingOptions = decodingInfo.getDecodingOptions();
   decodingOptions.inSampleSize = scale;
   return decodingOptions;
 }
Exemplo n.º 2
0
  protected Bitmap considerExactScaleAndOrientatiton(
      Bitmap subsampledBitmap,
      ImageDecodingInfo decodingInfo,
      int rotation,
      boolean flipHorizontal) {
    Matrix m = new Matrix();
    // Scale to exact size if need
    ImageScaleType scaleType = decodingInfo.getImageScaleType();
    if (scaleType == ImageScaleType.EXACTLY || scaleType == ImageScaleType.EXACTLY_STRETCHED) {
      ImageSize srcSize =
          new ImageSize(subsampledBitmap.getWidth(), subsampledBitmap.getHeight(), rotation);
      float scale =
          ImageSizeUtils.computeImageScale(
              srcSize,
              decodingInfo.getTargetSize(),
              decodingInfo.getViewScaleType(),
              scaleType == ImageScaleType.EXACTLY_STRETCHED);
      if (Float.compare(scale, 1f) != 0) {
        m.setScale(scale, scale);
      }
    }
    // Flip bitmap if need
    if (flipHorizontal) {
      m.postScale(-1, 1);
    }
    // Rotate bitmap if need
    if (rotation != 0) {
      m.postRotate(rotation);
    }

    Bitmap finalBitmap =
        Bitmap.createBitmap(
            subsampledBitmap,
            0,
            0,
            subsampledBitmap.getWidth(),
            subsampledBitmap.getHeight(),
            m,
            true);
    if (finalBitmap != subsampledBitmap) {
      subsampledBitmap.recycle();
    }
    return finalBitmap;
  }