欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

android 对图片做圆角处理 博客分类: android androidbmpround 

程序员文章站 2024-03-11 23:43:25
...
/*
private Bitmap outputRound(Bitmap bitmap){
if(bitmap == null)
return null;
int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    Bitmap localBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_4444);
    Canvas localCanvas = new Canvas(localBitmap);
   
    Path path = new Path();
    path.addRoundRect(new RectF(0,0,w,h), 6, 6, Path.Direction.CW);
    localCanvas.clipPath(path);
   
    localCanvas.drawBitmap(bitmap, 0.0F, 0.0F, null);   
    return localBitmap;
}
*/


private Bitmap outputRound1(Bitmap bitmap) {
if(bitmap == null)
return null;
int i = bitmap.getWidth();
int j = bitmap.getHeight();
Bitmap.Config localConfig = Bitmap.Config.ARGB_8888;
Bitmap localBitmap = Bitmap.createBitmap(i, j, localConfig);
Canvas localCanvas = new Canvas(localBitmap);
localCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
final int color = 0xff424242;  
    final Paint paint = new Paint();  
    Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());  
    RectF rectF = new RectF(rect);
   
    paint.setAntiAlias(true);  
    //localCanvas.drawARGB(0, 0, 0, 0);  
        //paint.setColor(color);  
        localCanvas.drawRoundRect(rectF, 10, 10, paint);  
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));  
        localCanvas.drawBitmap(bitmap, rect, rect,paint);
      
        return localBitmap;       
}
相关标签: android bmp round