本文整理了Java中android.graphics.Bitmap.setHasAlpha()
方法的一些代码示例,展示了Bitmap.setHasAlpha()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bitmap.setHasAlpha()
方法的具体详情如下:
包路径:android.graphics.Bitmap
类名称:Bitmap
方法名:setHasAlpha
暂无
代码示例来源:origin: bumptech/glide
private Bitmap getNextBitmap() {
Bitmap.Config config = isFirstFrameTransparent == null || isFirstFrameTransparent
? Bitmap.Config.ARGB_8888 : bitmapConfig;
Bitmap result = bitmapProvider.obtain(downsampledWidth, downsampledHeight, config);
result.setHasAlpha(true);
return result;
}
}
代码示例来源:origin: bumptech/glide
/**
* Sets the alpha of the Bitmap we're going to re-use to the alpha of the Bitmap we're going to
* transform. This keeps {@link android.graphics.Bitmap#hasAlpha()}} consistent before and after
* the transformation for transformations that don't add or remove transparent pixels.
*
* @param inBitmap The {@link android.graphics.Bitmap} that will be transformed.
* @param outBitmap The {@link android.graphics.Bitmap} that will be returned from the
* transformation.
*/
public static void setAlpha(Bitmap inBitmap, Bitmap outBitmap) {
outBitmap.setHasAlpha(inBitmap.hasAlpha());
}
代码示例来源:origin: bumptech/glide
private static void normalize(Bitmap bitmap) {
bitmap.setHasAlpha(true);
maybeSetPreMultiplied(bitmap);
}
代码示例来源:origin: wasabeef/glide-transformations
@Override
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
bitmap.setHasAlpha(true);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(toTransform, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
drawRoundRect(canvas, paint, width, height);
return bitmap;
}
代码示例来源:origin: wasabeef/glide-transformations
@Override
protected Bitmap transform(@NonNull Context context, @NonNull BitmapPool pool,
@NonNull Bitmap toTransform, int outWidth, int outHeight) {
int width = toTransform.getWidth();
int height = toTransform.getHeight();
Bitmap bitmap = pool.get(width, height, Bitmap.Config.ARGB_8888);
bitmap.setHasAlpha(true);
Drawable mask = Utils.getMaskDrawable(context.getApplicationContext(), maskId);
Canvas canvas = new Canvas(bitmap);
mask.setBounds(0, 0, width, height);
mask.draw(canvas);
canvas.drawBitmap(toTransform, 0, 0, paint);
return bitmap;
}
代码示例来源:origin: koral--/android-gif-drawable
/**
* Retrieves a copy of currently buffered frame.
*
* @return current frame
*/
public Bitmap getCurrentFrame() {
final Bitmap copy = mBuffer.copy(mBuffer.getConfig(), mBuffer.isMutable());
copy.setHasAlpha(mBuffer.hasAlpha());
return copy;
}
代码示例来源:origin: bumptech/glide
private Bitmap createBitmapWithRedCircle(int width, int height) {
int minEdge = Math.min(width, height);
float radius = minEdge / 2f;
Bitmap result = Bitmap.createBitmap(minEdge, minEdge, Bitmap.Config.ARGB_8888);
result.setHasAlpha(true);
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.RED);
canvas.drawCircle(radius, radius, radius, paint);
return result;
}
代码示例来源:origin: bumptech/glide
/**
* Rotate and/or flip the image to match the given exif orientation.
*
* @param pool A pool that may or may not contain an image of the necessary
* dimensions.
* @param inBitmap The bitmap to rotate/flip.
* @param exifOrientation the exif orientation [1-8].
* @return The rotated and/or flipped image or toOrient if no rotation or flip was necessary.
*/
public static Bitmap rotateImageExif(@NonNull BitmapPool pool, @NonNull Bitmap inBitmap,
int exifOrientation) {
if (!isExifOrientationRequired(exifOrientation)) {
return inBitmap;
}
final Matrix matrix = new Matrix();
initializeMatrixForRotation(exifOrientation, matrix);
// From Bitmap.createBitmap.
final RectF newRect = new RectF(0, 0, inBitmap.getWidth(), inBitmap.getHeight());
matrix.mapRect(newRect);
final int newWidth = Math.round(newRect.width());
final int newHeight = Math.round(newRect.height());
Bitmap.Config config = getNonNullConfig(inBitmap);
Bitmap result = pool.get(newWidth, newHeight, config);
matrix.postTranslate(-newRect.left, -newRect.top);
result.setHasAlpha(inBitmap.hasAlpha());
applyMatrix(inBitmap, result, matrix);
return result;
}
代码示例来源:origin: bumptech/glide
result.setHasAlpha(true);
代码示例来源:origin: bumptech/glide
@Test
public void
testFitCenterSetsOutBitmapToNotHaveAlphaIfInBitmapDoesNotHaveAlphaAndOutBitmapIsReused() {
Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Bitmap toReuse = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
reset(bitmapPool);
when(bitmapPool.get(eq(toReuse.getWidth()), eq(toReuse.getHeight()), eq(toReuse.getConfig())))
.thenReturn(toReuse);
toReuse.setHasAlpha(true);
toTransform.setHasAlpha(false);
Bitmap result = TransformationUtils.fitCenter(bitmapPool, toTransform, toReuse.getWidth(),
toReuse.getHeight());
assertEquals(toReuse, result);
assertFalse(result.hasAlpha());
}
代码示例来源:origin: bumptech/glide
@Test
public void testCenterCropSetsOutBitmapToHaveAlphaIfInBitmapHasAlphaAndOutBitmapIsReused() {
Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Bitmap toReuse = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
reset(bitmapPool);
when(bitmapPool.get(eq(50), eq(50), eq(Bitmap.Config.ARGB_8888)))
.thenReturn(toReuse);
toReuse.setHasAlpha(false);
toTransform.setHasAlpha(true);
Bitmap result = TransformationUtils.centerCrop(bitmapPool, toTransform, toReuse.getWidth(),
toReuse.getHeight());
assertEquals(toReuse, result);
assertTrue(result.hasAlpha());
}
代码示例来源:origin: bumptech/glide
@Test
public void
testCenterCropSetsOutBitmapToNotHaveAlphaIfInBitmapDoesNotHaveAlphaAndOutBitmapIsReused() {
Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Bitmap toReuse = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
reset(bitmapPool);
when(bitmapPool.get(eq(50), eq(50), eq(Bitmap.Config.ARGB_8888))).thenReturn(toReuse);
toReuse.setHasAlpha(true);
toTransform.setHasAlpha(false);
Bitmap result = TransformationUtils.centerCrop(bitmapPool, toTransform, toReuse.getWidth(),
toReuse.getHeight());
assertEquals(toReuse, result);
assertFalse(result.hasAlpha());
}
代码示例来源:origin: bumptech/glide
@Test
public void testFitCenterSetsOutBitmapToHaveAlphaIfInBitmapHasAlphaAndOutBitmapIsReused() {
Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Bitmap toReuse = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
reset(bitmapPool);
when(bitmapPool.get(eq(toReuse.getWidth()), eq(toReuse.getHeight()), eq(toReuse.getConfig())))
.thenReturn(toReuse);
toReuse.setHasAlpha(false);
toTransform.setHasAlpha(true);
Bitmap result = TransformationUtils.fitCenter(bitmapPool, toTransform, toReuse.getWidth(),
toReuse.getHeight());
assertEquals(toReuse, result);
assertTrue(result.hasAlpha());
}
代码示例来源:origin: bumptech/glide
@Test
public void testFitCenterSetsOutBitmapToHaveAlphaIfInBitmapHasAlpha() {
Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
toTransform.setHasAlpha(true);
Bitmap result = TransformationUtils.fitCenter(bitmapPool, toTransform,
toTransform.getWidth() / 2, toTransform.getHeight() / 2);
assertTrue(result.hasAlpha());
}
代码示例来源:origin: bumptech/glide
@Test
public void testCenterCropSetsOutBitmapToNotHaveAlphaIfInBitmapDoesNotHaveAlpha() {
Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
toTransform.setHasAlpha(false);
Bitmap result = TransformationUtils.centerCrop(bitmapPool, toTransform,
toTransform.getWidth() / 2, toTransform.getHeight() / 2);
assertFalse(result.hasAlpha());
}
代码示例来源:origin: bumptech/glide
@Test
public void testFitCenterSetsOutBitmapToNotHaveAlphaIfInBitmapDoesNotHaveAlpha() {
Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
toTransform.setHasAlpha(false);
Bitmap result = TransformationUtils.fitCenter(bitmapPool, toTransform,
toTransform.getWidth() / 2, toTransform.getHeight() / 2);
assertFalse(result.hasAlpha());
}
代码示例来源:origin: bumptech/glide
@Test
public void testCenterCropSetsOutBitmapToHaveAlphaIfInBitmapHasAlpha() {
Bitmap toTransform = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
toTransform.setHasAlpha(true);
Bitmap result = TransformationUtils.centerCrop(bitmapPool, toTransform,
toTransform.getWidth() / 2, toTransform.getHeight() / 2);
assertTrue(result.hasAlpha());
}
代码示例来源:origin: robolectric/robolectric
@Test
public void hasAlpha() {
Bitmap bitmap = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_8888);
assertThat(bitmap.hasAlpha()).isFalse();
bitmap.setHasAlpha(true);
assertThat(bitmap.hasAlpha()).isTrue();
}
代码示例来源:origin: bumptech/glide
@Test
public void testEncoderEncodesPngWithNullFormatAndBitmapWithAlpha() throws IOException {
harness.setFormat(null);
harness.bitmap.setHasAlpha(true);
assertThat(harness.encode()).isEqualTo(harness.expectedData(CompressFormat.PNG, 90));
}
代码示例来源:origin: bumptech/glide
@Test
public void testEncoderEncodesJpegWithNullFormatAndBitmapWithoutAlpha() throws IOException {
harness.setFormat(null);
harness.bitmap.setHasAlpha(false);
assertThat(harness.encode()).isEqualTo(harness.expectedData(CompressFormat.JPEG, 90));
}
内容来源于网络,如有侵权,请联系作者删除!