如何使图像的角落编程 [英] How to make an image corner programatically

查看:116
本文介绍了如何使图像的角落编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是文本view.It有一个形象background.I希望这一形象的角落rounded.Is有任何编程解决方案?任何人有任何想法。

I am using a text view.It has one image as background.I want this image's corner rounded.Is there any programatically solution? Anyone having any idea.

推荐答案

将您的图像位图,然后转换成带有圆角位图位图。最后的位图应用到你的TextView的背景。下面code是转换位图圆角位图图像。

Convert your image to bitmap and then convert that bitmap with rounded corners bitmap. Finally apply that bitmap to your textview background. The below code is for convert bitmap to rounded bitmap image.

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap,int roundPixelSize) { 
        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); 
        Canvas canvas = new Canvas(output); 
        final Paint paint = new Paint(); 
        final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); 
        final RectF rectF = new RectF(rect); 
        final float roundPx = roundPixelSize;
        paint.setAntiAlias(true);
        canvas.drawRoundRect(rectF,roundPx,roundPx, paint);
        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint); 
        return output; 
    }

这篇关于如何使图像的角落编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆