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

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

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

Bitmap.getConfig介绍

暂无

代码示例

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

@Nullable
@TargetApi(Build.VERSION_CODES.KITKAT)
private static String getBitmapString(Bitmap bitmap) {
 if (bitmap == null) {
  return null;
 }
 String sizeString = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
   ? " (" + bitmap.getAllocationByteCount() + ")" : "";
 return  "[" + bitmap.getWidth() + "x" + bitmap.getHeight() + "] " + bitmap.getConfig()
   + sizeString;
}

代码示例来源:origin: stackoverflow.com

private Bitmap addWhiteBorder(Bitmap bmp, int borderSize) {
  Bitmap bmpWithBorder = Bitmap.createBitmap(bmp.getWidth() + borderSize * 2, bmp.getHeight() + borderSize * 2, bmp.getConfig());
  Canvas canvas = new Canvas(bmpWithBorder);
  canvas.drawColor(Color.WHITE);
  canvas.drawBitmap(bmp, borderSize, borderSize, null);
  return bmpWithBorder;
}

代码示例来源:origin: stackoverflow.com

heightOfScreen, bitmap2.getConfig());
  paint.setXfermode(new PorterDuffXfermode(Mode.SRC_OUT));
canvas.drawBitmap(bitmap2, 0, 0, paint);
compositeImageView.setImageBitmap(resultingImage);

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

private static Bitmap getAlphaSafeBitmap(
  @NonNull BitmapPool pool, @NonNull Bitmap maybeAlphaSafe) {
 Bitmap.Config safeConfig = getAlphaSafeConfig(maybeAlphaSafe);
 if (safeConfig.equals(maybeAlphaSafe.getConfig())) {
  return maybeAlphaSafe;
 }
 Bitmap argbBitmap =
   pool.get(maybeAlphaSafe.getWidth(), maybeAlphaSafe.getHeight(), safeConfig);
 new Canvas(argbBitmap).drawBitmap(maybeAlphaSafe, 0 /*left*/, 0 /*top*/, null /*paint*/);
 // We now own this Bitmap. It's our responsibility to replace it in the pool outside this method
 // when we're finished with it.
 return argbBitmap;
}

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

private static String getBitmapString(Bitmap bitmap) {
 return getBitmapString(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
}

代码示例来源:origin: stackoverflow.com

canvas.drawBitmap(blurred, 0, 0, paint);
Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);

代码示例来源:origin: stackoverflow.com

public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
   Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
   Canvas canvas = new Canvas(bmOverlay);
   canvas.drawBitmap(bmp1, new Matrix(), null);
   canvas.drawBitmap(bmp2, 0, 0, null);
   return bmOverlay;
 }

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

@Override
public void put(Bitmap bitmap) {
 final Key key = keyPool.get(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
 groupedMap.put(key, 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.Config config =
   toTransform.getConfig() != null ? toTransform.getConfig() : Bitmap.Config.ARGB_8888;
 Bitmap bitmap = pool.get(width, height, config);
 Canvas canvas = new Canvas(bitmap);
 Paint paint = new Paint();
 paint.setAntiAlias(true);
 paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
 canvas.drawBitmap(toTransform, 0, 0, paint);
 return bitmap;
}

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

/**
 * Returns the in memory size of the given {@link Bitmap} in bytes.
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
public static int getBitmapByteSize(@NonNull Bitmap bitmap) {
 // The return value of getAllocationByteCount silently changes for recycled bitmaps from the
 // internal buffer size to row bytes * height. To avoid random inconsistencies in caches, we
 // instead assert here.
 if (bitmap.isRecycled()) {
  throw new IllegalStateException("Cannot obtain size for recycled Bitmap: " + bitmap
    + "[" + bitmap.getWidth() + "x" + bitmap.getHeight() + "] " + bitmap.getConfig());
 }
 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  // Workaround for KitKat initial release NPE in Bitmap, fixed in MR1. See issue #148.
  try {
   return bitmap.getAllocationByteCount();
  } catch (@SuppressWarnings("PMD.AvoidCatchingNPE") NullPointerException e) {
   // Do nothing.
  }
 }
 return bitmap.getHeight() * bitmap.getRowBytes();
}

代码示例来源:origin: stackoverflow.com

private Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
   Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
   Canvas canvas = new Canvas(bmOverlay);
   canvas.drawBitmap(bmp1, new Matrix(), null);
   canvas.drawBitmap(bmp2, new Matrix(), null);
   return bmOverlay;
 }

代码示例来源:origin: stackoverflow.com

@Override
public Bitmap transform(Bitmap source) {
  int size = Math.min(source.getWidth(), source.getHeight());
  int x = (source.getWidth() - size) / 2;
  int y = (source.getHeight() - size) / 2;
  Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());

代码示例来源:origin: cSploit/android

public Bitmap addLogo(Bitmap mainImage, Bitmap logoImage) {
  Bitmap finalImage;
  int width, height;
  width = mainImage.getWidth();
  height = mainImage.getHeight();
  finalImage = Bitmap.createBitmap(width, height,
      mainImage.getConfig());
  Canvas canvas = new Canvas(finalImage);
  canvas.drawBitmap(mainImage, 0, 0, null);
  canvas.drawBitmap(logoImage,
      canvas.getWidth() - logoImage.getWidth(),
      canvas.getHeight() - logoImage.getHeight(), null);
  return finalImage;
}

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

private static String getDisplayString(Bitmap bitmap) {
  return "<"
   + "[" + bitmap.getWidth() + "x" + bitmap.getHeight() + "]"
   + " "
   + bitmap.getConfig()
   + ">";
}

代码示例来源:origin: stackoverflow.com

public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
  Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
  Canvas canvas = new Canvas(bmOverlay);
  canvas.drawBitmap(bmp1, new Matrix(), null);
  canvas.drawBitmap(bmp2, 0, 0, null);
  return bmOverlay;
}

代码示例来源:origin: frogermcs/InstaMaterial

@Override
public Bitmap transform(Bitmap source) {
  int size = Math.min(source.getWidth(), source.getHeight());
  int x = (source.getWidth() - size) / 2;
  int y = (source.getHeight() - size) / 2;
  Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
  if (squaredBitmap != source) {
    source.recycle();
  }
  Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
  Canvas canvas = new Canvas(bitmap);
  Paint paint = new Paint();
  BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
  paint.setShader(shader);
  paint.setAntiAlias(true);
  float r = size / 2f;
  canvas.drawCircle(r, r, r, paint);
  squaredBitmap.recycle();
  return bitmap;
}

代码示例来源:origin: stackoverflow.com

int sourceWidth = source.getWidth();
int sourceHeight = source.getHeight();
Bitmap dest = Bitmap.createBitmap(newWidth, newHeight, source.getConfig());
Canvas canvas = new Canvas(dest);
canvas.drawBitmap(source, null, targetRect, null);

代码示例来源:origin: chentao0707/SimplifyReader

public static Bitmap doBlurJniArray(Bitmap sentBitmap, int radius, boolean canReuseInBitmap) {
  Bitmap bitmap;
  if (canReuseInBitmap) {
    bitmap = sentBitmap;
  } else {
    bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
  }
  if (radius < 1) {
    return (null);
  }
  int w = bitmap.getWidth();
  int h = bitmap.getHeight();
  int[] pix = new int[w * h];
  bitmap.getPixels(pix, 0, w, 0, 0, w, h);
  // Jni array calculate
  ImageBlur.blurIntArray(pix, w, h, radius);
  bitmap.setPixels(pix, 0, w, 0, 0, w, h);
  return (bitmap);
}

代码示例来源:origin: stackoverflow.com

public static Bitmap mark(Bitmap src, String watermark, Point location, Color color, int alpha, int size, boolean underline) {
int w = src.getWidth();
int h = src.getHeight();
Bitmap result = Bitmap.createBitmap(w, h, src.getConfig());

Canvas canvas = new Canvas(result);
canvas.drawBitmap(src, 0, 0, null);

Paint paint = new Paint();
paint.setColor(color);
paint.setAlpha(alpha);
paint.setTextSize(size);
paint.setAntiAlias(true);
paint.setUnderlineText(underline);
canvas.drawText(watermark, location.x, location.y, paint);

return result;
}

代码示例来源:origin: frogermcs/InstaMaterial

@Override
public Bitmap transform(Bitmap source) {
  int size = Math.min(source.getWidth(), source.getHeight());
  int x = (source.getWidth() - size) / 2;
  int y = (source.getHeight() - size) / 2;
  Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
  if (squaredBitmap != source) {
    source.recycle();
  }
  Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
  Canvas canvas = new Canvas(bitmap);
  Paint avatarPaint = new Paint();
  BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
  avatarPaint.setShader(shader);
  Paint outlinePaint = new Paint();
  outlinePaint.setColor(Color.WHITE);
  outlinePaint.setStyle(Paint.Style.STROKE);
  outlinePaint.setStrokeWidth(STROKE_WIDTH);
  outlinePaint.setAntiAlias(true);
  float r = size / 2f;
  canvas.drawCircle(r, r, r, avatarPaint);
  canvas.drawCircle(r, r, r - STROKE_WIDTH / 2, outlinePaint);
  squaredBitmap.recycle();
  return bitmap;
}

相关文章