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

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

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

Bitmap.getHeight介绍

暂无

代码示例

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

public static Bitmap rotateImage(Bitmap source, float angle) {
  Matrix matrix = new Matrix();
  matrix.postRotate(angle);
  return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(),
                matrix, true);
}

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

@Override
public void add(Bitmap bitmap) {
 if (bitmaps.contains(bitmap)) {
  throw new IllegalStateException(
    "Can't add already added bitmap: " + bitmap + " [" + bitmap.getWidth() + "x" + bitmap
      .getHeight() + "]");
 }
 bitmaps.add(bitmap);
}

代码示例来源:origin: nostra13/Android-Universal-Image-Loader

public RoundedDrawable(Bitmap bitmap, int cornerRadius, int margin) {
  this.cornerRadius = cornerRadius;
  this.margin = margin;
  bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
  mBitmapRect = new RectF (margin, margin, bitmap.getWidth() - margin, bitmap.getHeight() - margin);
  
  paint = new Paint();
  paint.setAntiAlias(true);
  paint.setShader(bitmapShader);
  paint.setFilterBitmap(true);
  paint.setDither(true);
}

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

public Bitmap getCroppedBitmap(Bitmap bitmap) {
  Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
      bitmap.getHeight(), Config.ARGB_8888);
  Canvas canvas = new Canvas(output);

  final int color = 0xff424242;
  final Paint paint = new Paint();
  final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

  paint.setAntiAlias(true);
  canvas.drawARGB(0, 0, 0, 0);
  paint.setColor(color);
  // canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
  canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,
      bitmap.getWidth() / 2, paint);
  paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
  canvas.drawBitmap(bitmap, rect, rect, paint);
  //Bitmap _bmp = Bitmap.createScaledBitmap(output, 60, 60, false);
  //return _bmp;
  return output;
}

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

ImageView mImageView= (ImageView)findViewById(R.id.imageview_id);
Bitmap original = BitmapFactory.decodeResource(getResources(),R.drawable.content_image);
Bitmap mask = BitmapFactory.decodeResource(getResources(),R.drawable.mask);
Bitmap result = Bitmap.createBitmap(mask.getWidth(), mask.getHeight(), Config.ARGB_8888);
Canvas mCanvas = new Canvas(result);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
mCanvas.drawBitmap(original, 0, 0, null);
mCanvas.drawBitmap(mask, 0, 0, paint);
paint.setXfermode(null);
mImageView.setImageBitmap(result);
mImageView.setScaleType(ScaleType.CENTER);
mImageView.setBackgroundResource(R.drawable.background_frame);

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

public BitmapDrawable writeOnDrawable(int drawableId, String text){
   Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId).copy(Bitmap.Config.ARGB_8888, true);
   Paint paint = new Paint(); 
   paint.setStyle(Style.FILL);  
   paint.setColor(Color.BLACK); 
   paint.setTextSize(20); 
   Canvas canvas = new Canvas(bm);
   canvas.drawText(text, 0, bm.getHeight()/2, paint);
   return new BitmapDrawable(bm);
 }

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

public Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) {
  int width = bm.getWidth();
  int height = bm.getHeight();
  float scaleWidth = ((float) newWidth) / width;
  float scaleHeight = ((float) newHeight) / height;
  // CREATE A MATRIX FOR THE MANIPULATION
  Matrix matrix = new Matrix();
  // RESIZE THE BIT MAP
  matrix.postScale(scaleWidth, scaleHeight);

  // "RECREATE" THE NEW BITMAP
  Bitmap resizedBitmap = Bitmap.createBitmap(
    bm, 0, 0, width, height, matrix, false);
  bm.recycle();
  return resizedBitmap;
}

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

Bitmap myCoolBitmap = ... ; // <-- Your bitmap you want rounded    
int w = myCoolBitmap.getWidth(), h = myCoolBitmap.getHeight();

// We have to make sure our rounded corners have an alpha channel in most cases
Bitmap rounder = Bitmap.createBitmap(w,h,Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(rounder);    

// We're going to apply this paint eventually using a porter-duff xfer mode.
// This will allow us to only overwrite certain pixels. RED is arbitrary. This
// could be any color that was fully opaque (alpha = 255)
Paint xferPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
xferPaint.setColor(Color.RED);

// We're just reusing xferPaint to paint a normal looking rounded box, the 20.f
// is the amount we're rounding by.
canvas.drawRoundRect(new RectF(0,0,w,h), 20.0f, 20.0f, xferPaint);     

// Now we apply the 'magic sauce' to the paint  
xferPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));

代码示例来源:origin: navasmdc/MaterialDesignLibrary

public Bitmap cropCircle(Bitmap bitmap) {
  Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
      bitmap.getHeight(), Config.ARGB_8888);
  Canvas canvas = new Canvas(output);
  final int color = 0xff424242;
  final Paint paint = new Paint();
  final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
  paint.setAntiAlias(true);
  canvas.drawARGB(0, 0, 0, 0);
  paint.setColor(color);
  canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,
      bitmap.getWidth()/2, paint);
  paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
  canvas.drawBitmap(bitmap, rect, rect, paint);
  return output;
}

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

Matrix matrix = new Matrix();

matrix.postRotate(90);

Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmapOrg,width,height,true);

Bitmap rotatedBitmap = Bitmap.createBitmap(scaledBitmap , 0, 0, scaledBitmap .getWidth(), scaledBitmap .getHeight(), matrix, true);

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

Bitmap bitmap = getthebitmapyouwanttoshowinacirclefromsomewhere;
Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);

BitmapShader shader = new BitmapShader (bitmap,  TileMode.CLAMP, TileMode.CLAMP);
Paint paint = new Paint();
    paint.setShader(shader);
paint.setAntiAlias(true);
Canvas c = new Canvas(circleBitmap);
c.drawCircle(bitmap.getWidth()/2, bitmap.getHeight()/2, bitmap.getWidth()/2, paint);

myImageView.setImageBitmap(circleBitmap);

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

public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth)
{
  int width = bm.getWidth();
  int height = bm.getHeight();
  float scaleWidth = ((float) newWidth) / width;
  float scaleHeight = ((float) newHeight) / height;
  // create a matrix for the manipulation
  Matrix matrix = new Matrix();
  // resize the bit map
  matrix.postScale(scaleWidth, scaleHeight);
  // recreate the new Bitmap
  Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
  return resizedBitmap;
}

代码示例来源:origin: hdodenhof/CircleImageView

mBorderPaint.setColor(mBorderColor);
mBorderPaint.setStrokeWidth(mBorderWidth);
mCircleBackgroundPaint.setColor(mCircleBackgroundColor);
mBitmapHeight = mBitmap.getHeight();
mBitmapWidth = mBitmap.getWidth();

代码示例来源:origin: nostra13/Android-Universal-Image-Loader

public CircleDrawable(Bitmap bitmap, Integer strokeColor, float strokeWidth) {
  radius = Math.min(bitmap.getWidth(), bitmap.getHeight()) / 2;
  bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
  mBitmapRect = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
  paint = new Paint();
  paint.setAntiAlias(true);
  paint.setShader(bitmapShader);
  paint.setFilterBitmap(true);
  paint.setDither(true);
  if (strokeColor == null) {
    strokePaint = null;
  } else {
    strokePaint = new Paint();
    strokePaint.setStyle(Paint.Style.STROKE);
    strokePaint.setColor(strokeColor);
    strokePaint.setStrokeWidth(strokeWidth);
    strokePaint.setAntiAlias(true);
  }
  this.strokeWidth = strokeWidth;
  strokeRadius = radius - strokeWidth / 2;
}

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

public static Bitmap RotateBitmap(Bitmap source, float angle)
{
   Matrix matrix = new Matrix();
   matrix.postRotate(angle);
   return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}

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

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

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

private static Bitmap roundCrop(BitmapPool pool, Bitmap source) {
  if (source == null) return null;
  Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
  if (result == null) {
    result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
  }
  Canvas canvas = new Canvas(result);
  Paint paint = new Paint();
  paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
  paint.setAntiAlias(true);
  RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight());
  canvas.drawRoundRect(rectF, radius, radius, paint);
  return result;
}

相关文章