本文整理汇总了Java中android.graphics.Bitmap.Config方法的典型用法代码示例。如果您正苦于以下问题:Java Bitmap.Config方法的具体用法?Java Bitmap.Config怎么用?Java Bitmap.Config使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Bitmap
的用法示例。
在下文中一共展示了Bitmap.Config方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decodeGif
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* Decodes a GIF into a CloseableImage.
* @param encodedImage encoded image (native byte array holding the encoded bytes and meta data)
* @param options the options for the decode
* @param bitmapConfig the Bitmap.Config used to generate the output bitmaps
* @return a {@link CloseableImage} for the GIF image
*/
public CloseableImage decodeGif(
final EncodedImage encodedImage,
final ImageDecodeOptions options,
final Bitmap.Config bitmapConfig) {
if (sGifAnimatedImageDecoder == null) {
throw new UnsupportedOperationException("To encode animated gif please add the dependency " +
"to the animated-gif module");
}
final CloseableReference<PooledByteBuffer> bytesRef = encodedImage.getByteBufferRef();
Preconditions.checkNotNull(bytesRef);
try {
final PooledByteBuffer input = bytesRef.get();
AnimatedImage gifImage = sGifAnimatedImageDecoder.decode(input.getNativePtr(), input.size());
return getCloseableImage(options, gifImage, bitmapConfig);
} finally {
CloseableReference.closeSafely(bytesRef);
}
}
示例2: 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;
}
示例3: getBitmapSizeInBytes
import android.graphics.Bitmap; //导入方法依赖的package包/类
public static long getBitmapSizeInBytes(Bitmap bitmap) {
if (bitmap == null || bitmap.isRecycled())
return 0L;
Bitmap.Config config = bitmap.getConfig();
switch (config) {
case ARGB_8888:
return ARGB_8888_BYTES_PER_PIXEL * getSizeInBytes(bitmap);
case ALPHA_8:
return ALPHA_8_BYTES_PER_PIXEL * getSizeInBytes(bitmap);
case ARGB_4444:
return ARGB_4444_BYTES_PER_PIXEL * getSizeInBytes(bitmap);
case RGB_565:
return RGB_565_BYTES_PER_PIXEL * getSizeInBytes(bitmap);
}
throw new TinyException.UnsupportedParamException("this bitmap config is not supported!");
}
示例4: drawable2Bitmap
import android.graphics.Bitmap; //导入方法依赖的package包/类
private static Bitmap drawable2Bitmap(Drawable drawable) {
if (drawable == null) {
return null;
}
// 取 drawable 的长宽
int w = drawable.getIntrinsicWidth();
int h = drawable.getIntrinsicHeight();
// 取 drawable 的颜色格式
Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE
? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565;
// 建立对应 bitmap
Bitmap bitmap = Bitmap.createBitmap(w, h, config);
// 建立对应 bitmap 的画布
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, w, h);
// 把 drawable 内容画到画布中
drawable.draw(canvas);
return bitmap;
}
示例5: decodeFromEncodedImage
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* Creates a bitmap from encoded bytes.
*
* @param encodedImage the encoded image with a reference to the encoded bytes
* @param bitmapConfig the {@link android.graphics.Bitmap.Config} used to create the decoded
* Bitmap
* @param regionToDecode optional image region to decode or null to decode the whole image
* @return the bitmap
* @exception java.lang.OutOfMemoryError if the Bitmap cannot be allocated
*/
@Override
public CloseableReference<Bitmap> decodeFromEncodedImage(
EncodedImage encodedImage, Bitmap.Config bitmapConfig, @Nullable Rect regionToDecode) {
final BitmapFactory.Options options = getDecodeOptionsForStream(encodedImage, bitmapConfig);
boolean retryOnFail=options.inPreferredConfig != Bitmap.Config.ARGB_8888;
try {
return decodeStaticImageFromStream(encodedImage.getInputStream(), options, regionToDecode);
} catch (RuntimeException re) {
if (retryOnFail) {
return decodeFromEncodedImage(encodedImage, Bitmap.Config.ARGB_8888, regionToDecode);
}
throw re;
}
}
示例6: getDirty
import android.graphics.Bitmap; //导入方法依赖的package包/类
@NonNull
@Override
public Bitmap getDirty(int width, int height, Bitmap.Config config) {
Bitmap result = getDirtyOrNull(width, height, config);
if (result == null) {
result = Bitmap.createBitmap(width, height, config);
}
return result;
}
示例7: newBitmap
import android.graphics.Bitmap; //导入方法依赖的package包/类
public static Bitmap newBitmap(int width, int height,Bitmap.Config config) {
try {
Bitmap bitmap = Bitmap.createBitmap(width, height,config);
return bitmap;
} catch (Throwable localThrowable) {
LogUtil.e(TAG, localThrowable.getMessage());
}
return null;
}
示例8: logBitmap
import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override
public String logBitmap(int width, int height, Bitmap.Config config) {
return null;
}
示例9: init
import android.graphics.Bitmap; //导入方法依赖的package包/类
public void init(int size, Bitmap.Config config) {
this.size = size;
this.config = config;
}
示例10: decodeBitmap
import android.graphics.Bitmap; //导入方法依赖的package包/类
public static ANResponse<Bitmap> decodeBitmap(Response response, int maxWidth,
int maxHeight, Bitmap.Config decodeConfig,
ImageView.ScaleType scaleType) {
return decodeBitmap(response, maxWidth, maxHeight, decodeConfig,
new BitmapFactory.Options(), scaleType);
}
示例11: getConfig
import android.graphics.Bitmap; //导入方法依赖的package包/类
public Bitmap.Config getConfig() {
return config;
}
示例12: createMutableBitmap
import android.graphics.Bitmap; //导入方法依赖的package包/类
private Bitmap createMutableBitmap(Bitmap.Config config) {
Bitmap bitmap = ShadowBitmap.createBitmap(100, 100, config);
Shadows.shadowOf(bitmap).setMutable(true);
return bitmap;
}
示例13: createRect
import android.graphics.Bitmap; //导入方法依赖的package包/类
private Bitmap createRect(int color, int width, int height, Bitmap.Config config) {
final Bitmap result = Bitmap.createBitmap(width, height, config);
Canvas canvas = new Canvas(result);
canvas.drawColor(color);
return result;
}
示例14: logBitmap
import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override
public String logBitmap(int width, int height, Bitmap.Config config) {
int size = Util.getBitmapByteSize(width, height, config);
return getBitmapString(size, config);
}
示例15: createBitmap
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* Creates a bitmap with the specified width and height. Its initial density is
* determined from the given DisplayMetrics.
*
* @param colors The colors to write to the bitmap
* @param width The width of the bitmap
* @param height The height of the bitmap
* @param config The bitmap config to create
* @param callerContext the Tag to track who create the Bitmap
* @return a reference to the bitmap
* @throws TooManyBitmapsException if the pool is full
* @throws java.lang.OutOfMemoryError if the Bitmap cannot be allocated
*/
public CloseableReference<Bitmap> createBitmap(
int[] colors,
int width,
int height,
Bitmap.Config config,
@Nullable Object callerContext) {
CloseableReference<Bitmap> bitmapRef = createBitmapInternal(width, height, config);
Bitmap bitmap = bitmapRef.get();
bitmap.setPixels(colors, 0, width, 0, 0, width, height);
addBitmapReference(bitmapRef.get(), callerContext);
return bitmapRef;
}