Java Code Examples for android.graphics.Bitmap.reconfigure()

The following are Jave code examples for showing how to use reconfigure() of the android.graphics.Bitmap class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GitHub   File: SizeStrategy.java   View Source Code Vote up 6 votes
@Override
@Nullable
public Bitmap get(int width, int height, Bitmap.Config config) {
  final int size = Util.getBitmapByteSize(width, height, config);
  Key key = keyPool.get(size);

  Integer possibleSize = sortedSizes.ceilingKey(size);
  if (possibleSize != null && possibleSize != size && possibleSize <= size * MAX_SIZE_MULTIPLE) {
    keyPool.offer(key);
    key = keyPool.get(possibleSize);
  }

  // Do a get even if we know we don't have a bitmap so that the key moves to the front in the
  // lru pool
  final Bitmap result = groupedMap.get(key);
  if (result != null) {
    result.reconfigure(width, height, config);
    decrementBitmapOfSize(possibleSize);
  }

  return result;
}
 
Example 2
Project: GitHub   File: SizeStrategy.java   View Source Code Vote up 6 votes
@Override
@Nullable
public Bitmap get(int width, int height, Bitmap.Config config) {
  final int size = Util.getBitmapByteSize(width, height, config);
  Key key = keyPool.get(size);

  Integer possibleSize = sortedSizes.ceilingKey(size);
  if (possibleSize != null && possibleSize != size && possibleSize <= size * MAX_SIZE_MULTIPLE) {
    keyPool.offer(key);
    key = keyPool.get(possibleSize);
  }

  // Do a get even if we know we don't have a bitmap so that the key moves to the front in the
  // lru pool
  final Bitmap result = groupedMap.get(key);
  if (result != null) {
    result.reconfigure(width, height, config);
    decrementBitmapOfSize(possibleSize);
  }

  return result;
}
 
Example 3
Project: GitHub   File: SizeConfigStrategy.java   View Source Code Vote up 5 votes
@Override
@Nullable
public Bitmap get(int width, int height, Bitmap.Config config) {
  int size = Util.getBitmapByteSize(width, height, config);
  Key bestKey = findBestKey(size, config);

  Bitmap result = groupedMap.get(bestKey);
  if (result != null) {
    // Decrement must be called before reconfigure.
    decrementBitmapOfSize(bestKey.size, result);
    result.reconfigure(width, height,
        result.getConfig() != null ? result.getConfig() : Bitmap.Config.ARGB_8888);
  }
  return result;
}
 
Example 4
Project: GitHub   File: SizeConfigStrategy.java   View Source Code Vote up 5 votes
@Override
@Nullable
public Bitmap get(int width, int height, Bitmap.Config config) {
  int size = Util.getBitmapByteSize(width, height, config);
  Key bestKey = findBestKey(size, config);

  Bitmap result = groupedMap.get(bestKey);
  if (result != null) {
    // Decrement must be called before reconfigure.
    decrementBitmapOfSize(bestKey.size, result);
    result.reconfigure(width, height,
        result.getConfig() != null ? result.getConfig() : Bitmap.Config.ARGB_8888);
  }
  return result;
}
 
Example 5
Project: GitHub   File: Bitmaps.java   View Source Code Vote up 5 votes
/**
 * Reconfigures bitmap after checking its allocation size.
 *
 * <p> This method is here to overcome our testing framework limit. Robolectric does not provide
 * KitKat specific APIs: {@link Bitmap#reconfigure} and {@link Bitmap#getAllocationByteCount}
 * are part of that.
 */
@TargetApi(19)
public static void reconfigureBitmap(
    Bitmap bitmap,
    int width,
    int height,
    Bitmap.Config bitmapConfig) {
  Preconditions.checkArgument(
      bitmap.getAllocationByteCount() >=
          width * height * BitmapUtil.getPixelSizeForBitmapConfig(bitmapConfig));
  bitmap.reconfigure(width, height, bitmapConfig);
}
 
Example 6
Project: LaunchEnr   File: WidgetPreviewLoader.java   View Source Code Vote up 5 votes
private Bitmap generateShortcutPreview(BaseActivity launcher, ShortcutConfigActivityInfo info,
        int maxWidth, int maxHeight, Bitmap preview) {
    int iconSize = launcher.getDeviceProfile().iconSizePx;
    int padding = launcher.getResources()
            .getDimensionPixelSize(R.dimen.widget_preview_shortcut_padding);

    int size = iconSize + 2 * padding;
    if (maxHeight < size || maxWidth < size) {
        throw new RuntimeException("Max size is too small for preview");
    }
    final Canvas c = new Canvas();
    if (preview == null || preview.getWidth() < size || preview.getHeight() < size) {
        preview = Bitmap.createBitmap(size, size, Config.ARGB_8888);
        c.setBitmap(preview);
    } else {
        if (preview.getWidth() > size || preview.getHeight() > size) {
            preview.reconfigure(size, size, preview.getConfig());
        }

        // Reusing bitmap. Clear it.
        c.setBitmap(preview);
        c.drawColor(0, PorterDuff.Mode.CLEAR);
    }
    Paint p = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
    RectF boxRect = drawBoxWithShadow(c, p, size, size);

    Bitmap icon = LauncherIcons.createScaledBitmapWithoutShadow(
            mutateOnMainThread(info.getFullResIcon(mIconCache)), mContext, Build.VERSION_CODES.O);
    Rect src = new Rect(0, 0, icon.getWidth(), icon.getHeight());

    boxRect.set(0, 0, iconSize, iconSize);
    boxRect.offset(padding, padding);
    c.drawBitmap(icon, src, boxRect, p);
    c.setBitmap(null);
    return preview;
}
 
Example 7
Project: GitHub   File: ArtDecoder.java   View Source Code Vote up 4 votes
protected CloseableReference<Bitmap> decodeStaticImageFromStream(
    InputStream inputStream, BitmapFactory.Options options, @Nullable Rect regionToDecode) {
  Preconditions.checkNotNull(inputStream);
  int targetWidth = options.outWidth;
  int targetHeight = options.outHeight;
  if (regionToDecode != null) {
    targetWidth = regionToDecode.width();
    targetHeight = regionToDecode.height();
  }
  int sizeInBytes =
      BitmapUtil.getSizeInByteForBitmap(targetWidth, targetHeight, options.inPreferredConfig);
  final Bitmap bitmapToReuse = mBitmapPool.get(sizeInBytes);
  if (bitmapToReuse == null) {
    throw new NullPointerException("BitmapPool.get returned null");
  }
  options.inBitmap = bitmapToReuse;

  Bitmap decodedBitmap = null;
  ByteBuffer byteBuffer = mDecodeBuffers.acquire();
  if (byteBuffer == null) {
    byteBuffer = ByteBuffer.allocate(DECODE_BUFFER_SIZE);
  }
  try {
    options.inTempStorage = byteBuffer.array();
    if (regionToDecode != null) {
      BitmapRegionDecoder bitmapRegionDecoder = null;
      try {
        bitmapToReuse.reconfigure(targetWidth, targetHeight, options.inPreferredConfig);
        bitmapRegionDecoder = BitmapRegionDecoder.newInstance(inputStream, true);
        decodedBitmap = bitmapRegionDecoder.decodeRegion(regionToDecode, options);
      } catch (IOException e) {
        FLog.e(TAG, "Could not decode region %s, decoding full bitmap instead.", regionToDecode);
      } finally {
        if (bitmapRegionDecoder != null) {
          bitmapRegionDecoder.recycle();
        }
      }
    }
    if (decodedBitmap == null) {
      decodedBitmap = BitmapFactory.decodeStream(inputStream, null, options);
    }
  } catch (RuntimeException re) {
    mBitmapPool.release(bitmapToReuse);
    throw re;
  } finally {
    mDecodeBuffers.release(byteBuffer);
  }

  if (bitmapToReuse != decodedBitmap) {
    mBitmapPool.release(bitmapToReuse);
    decodedBitmap.recycle();
    throw new IllegalStateException();
  }

  return CloseableReference.of(decodedBitmap, mBitmapPool);
}