首页 > 安全资讯 >

android图片转,圆形和圆角矩形

12-04-28

android 图片转 圆形和圆角矩形,比较高效的方法圆角矩形:int w = getWidth(); int h = getHeight(); Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas canvas ...

android 图片转 圆形和圆角矩形,比较高效的方法
圆角矩形:
int w = getWidth();
        int h = getHeight();
        Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        Paint paint = new Paint(1);
        paint.setColor(0xff000000);
        RectF rectf = new RectF(0F, 0F, w, h);
        canvas.drawRoundRect(rectf, cornerRadius, cornerRadius, paint);
        return bitmap;

圆形:

int w = getWidth();
        int h = getHeight();
        Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        Paint paint = new Paint(1);
        paint.setColor(0xff000000);
        RectF rectf = new RectF(0F, 0F, w, h);
        canvas.drawOval(rectf, paint);
        return bitmap;


摘自 刘群博客
相关文章
最新文章
热点推荐