用canvas画只有一个角是圆角的矩形,能画出来么?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用canvas画只有一个角是圆角的矩形,能画出来么?相关的知识,希望对你有一定的参考价值。

求各位大侠指点,谢谢

参考技术A public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) 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()); final RectF rectF = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; 查看原帖>>本回答被提问者采纳 参考技术B int x = 10; int y = 10; int width = 300; int height = 50; float[] outerR = new float[] 12, 12, 0, 0, 0, 0, 30, 30 ; RoundRectShape rectShape=new RoundRectShape(outerR, null, null); ShapeDrawable mDrawables= new ShapeDrawable(new RoundRectShape(outerR, null,null)); mDrawables.getPaint().setColor(Color.RED); mDrawables.setBounds(x, y, x + width, y + height); mDrawables.draw(canvas);费了九牛二虎之力终于找到点踪迹了,基本上搞定 参考技术C 找到方法了float[] radii=12f,12f,0f,0f,0f,0f,0f,0f;path.addRoundRect(new RectF(0, 0, 50, 50), radii, Path.Direction.CW);canvas.drawPath(path,paint); 查看原帖>> 参考技术D int x = 10; int y = 10; int width = 300; int height = 50; float[] outerR = new float[] 12, 12, 0, 0, 0, 0, 30, 30 ; RoundRectShape rectShape=new RoundRectShape(outerR, null, null); ShapeDrawable mDrawables= new ShapeDrawable(new RoundRectShape(outerR, null,null)); mDrawables.getPaint().setColor(Color.RED); mDrawables.setBounds(x, y, x + width, y + height); mDrawables.draw(canvas);费了九牛二虎之力终于找到点踪迹了,基本上搞定 查看原帖>> 第5个回答  2014-05-01 int x = 10; int y = 10; int width = 300; int height = 50; float[] outerR = new float[] 12, 12, 0, 0, 0, 0, 30, 30 ; RoundRectShape rectShape=new RoundRectShape(outerR, null, null); ShapeDrawable mDrawables= new ShapeDrawable(new RoundRectShape(outerR, null,null)); mDrawables.getPaint().setColor(Color.RED); mDrawables.setBounds(x, y, x + width, y + height); mDrawables.draw(canvas);费了九牛二虎之力终于找到点踪迹了,基本上搞定 查看原帖>>

以上是关于用canvas画只有一个角是圆角的矩形,能画出来么?的主要内容,如果未能解决你的问题,请参考以下文章

Android:如下关于绘制圆角矩形边框问题,怎么解决?

Android 里canvas 绘制了两个矩形,交叉位置颜色重叠

canvas绘制圆角矩形

MFC如何画矩形

如何使用shape来画半圆和画虚线

canvas 踩坑记录