本文整理汇总了Java中android.graphics.Bitmap.reconfigure方法的典型用法代码示例。如果您正苦于以下问题:Java Bitmap.reconfigure方法的具体用法?Java Bitmap.reconfigure怎么用?Java Bitmap.reconfigure使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Bitmap
的用法示例。
在下文中一共展示了Bitmap.reconfigure方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import android.graphics.Bitmap; //导入方法依赖的package包/类
@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;
}
示例2: get
import android.graphics.Bitmap; //导入方法依赖的package包/类
@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;
}
示例3: reconfigureBitmap
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* 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);
}
示例4: generateShortcutPreview
import android.graphics.Bitmap; //导入方法依赖的package包/类
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;
}
示例5: decodeStaticImageFromStream
import android.graphics.Bitmap; //导入方法依赖的package包/类
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);
}