25 Haziran 2015 Perşembe

Androidde bitmap resmi yuvarlak ve borderli yapmak


 /**
  * Resmi yuvarlak ve borderli hale çevirir
  * @param bitmap çevirilecek resim
  * @param borderWidth border genişliği
  * @return
  */
 private Bitmap getBitmapWithBorder(Bitmap bitmap,
   int borderWidth) {
  if (bitmap == null || bitmap.isRecycled()) {
   return null;
  }

  final int width = bitmap.getWidth() + borderWidth;
  final int height = bitmap.getHeight() + borderWidth;

  Bitmap canvasBitmap = Bitmap.createBitmap(width, height,
    Bitmap.Config.ARGB_8888);
  BitmapShader shader = new BitmapShader(bitmap, TileMode.CLAMP,
    TileMode.CLAMP);
  Paint paint = new Paint();
  paint.setAntiAlias(true);
  paint.setShader(shader);

  Canvas canvas = new Canvas(canvasBitmap);
  float radius = width > height ? ((float) height) / 2f
    : ((float) width) / 2f;
  canvas.drawCircle(width / 2, height / 2, radius, paint);
  paint.setShader(null);
  paint.setStyle(Paint.Style.STROKE);
  paint.setColor(getResources().getColor(R.color.darker_gray));
  paint.setStrokeWidth(borderWidth);
  canvas.drawCircle(width / 2, height / 2, radius - borderWidth / 2,
    paint);
  return canvasBitmap;
 }

Hiç yorum yok:

Yorum Gönder