android.graphics.Bitmap.hasAlpha()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(216)

本文整理了Java中android.graphics.Bitmap.hasAlpha()方法的一些代码示例,展示了Bitmap.hasAlpha()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bitmap.hasAlpha()方法的具体详情如下:
包路径:android.graphics.Bitmap
类名称:Bitmap
方法名:hasAlpha

Bitmap.hasAlpha介绍

暂无

代码示例

代码示例来源:origin: bumptech/glide

private Bitmap.CompressFormat getFormat(Bitmap bitmap, Options options) {
 Bitmap.CompressFormat format = options.get(COMPRESSION_FORMAT);
 if (format != null) {
  return format;
 } else if (bitmap.hasAlpha()) {
  return Bitmap.CompressFormat.PNG;
 } else {
  return Bitmap.CompressFormat.JPEG;
 }
}

代码示例来源: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: 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: square/assertj-android

public BitmapAssert hasAlphaSupport() {
 isNotNull();
 assertThat(actual.hasAlpha()) //
   .overridingErrorMessage("Expected to have alpha support but did not have it.") //
   .isTrue();
 return this;
}

代码示例来源:origin: square/assertj-android

public BitmapAssert hasNoAlphaSupport() {
 isNotNull();
 assertThat(actual.hasAlpha()) //
   .overridingErrorMessage("Expected to not have alpha support but had it.") //
   .isFalse();
 return this;
}

代码示例来源: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

+ " in " + LogTime.getElapsedMillis(start)
+ ", options format: " + options.get(COMPRESSION_FORMAT)
+ ", hasAlpha: " + bitmap.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
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: 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 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 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 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: 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: guolindev/giffun

private Bitmap.CompressFormat getFormat(Bitmap bitmap) {
  if (compressFormat != null) {
    return compressFormat;
  } else if (bitmap.hasAlpha()) {
    return Bitmap.CompressFormat.PNG;
  } else {
    return Bitmap.CompressFormat.JPEG;
  }
}

代码示例来源:origin: guolindev/giffun

@Override
public int getOpacity() {
  Bitmap bm = state.bitmap;
  return bm == null || bm.hasAlpha() || state.paint.getAlpha() < 255
      ? PixelFormat.TRANSLUCENT : PixelFormat.OPAQUE;
}

代码示例来源:origin: guolindev/giffun

/**
 * 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 Bitmap#hasAlpha()}} consistent before and after the transformation for
 * transformations that don't add or remove transparent pixels.
 *
 * @param toTransform The {@link Bitmap} that will be transformed.
 * @param outBitmap The {@link Bitmap} that will be returned from the transformation.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public static void setAlpha(Bitmap toTransform, Bitmap outBitmap) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1 && outBitmap != null) {
    outBitmap.setHasAlpha(toTransform.hasAlpha());
  }
}

代码示例来源:origin: ChillingVan/android-openGL-canvas

protected void throwIfCannotDraw(Bitmap bitmap) {
  if (bitmap.isRecycled()) {
    throw new RuntimeException("Canvas: trying to use a recycled bitmap " + bitmap);
  }
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    if (!bitmap.isPremultiplied() && bitmap.getConfig() == Bitmap.Config.ARGB_8888 &&
        bitmap.hasAlpha()) {
      throw new RuntimeException("Canvas: trying to use a non-premultiplied bitmap "
          + bitmap);
    }
  }
}

相关文章