I'm new to Android, and I would like to know how to draw this blue shape:
我是Android新手,我想知道如何绘制这个蓝色形状:
Without using images, of course.
当然,不使用图像。
Thanks!
谢谢!
1 个解决方案
#1
1
The easy way would be your suggested solution, ie. drawing all circles with no alpha to a bitmap, then draw that bitmap to another one using the desired alpha. The hard way would be using blend modes, specifically PorterDuff.Mode in Android. An example can be found here.
简单的方法是你建议的解决方案,即。将所有没有alpha的圆绘制到位图,然后使用所需的alpha将该位图绘制到另一个位图。困难的方法是使用混合模式,特别是Android中的PorterDuff.Mode。这里有一个例子。
Also Check this http://softwyer.wordpress.com/2012/01/21/1009/
另请查看http://softwyer.wordpress.com/2012/01/21/1009/
An example
一个例子
Bitmap bitmap = Bitmap.createBitmap(b.getWidth(), b.getHeight(), b.getConfig());
Canvas canvas = new Canvas(bitmap);
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
p.setColor(Color.BLACK);
canvas.drawRoundRect(new RectF(0, 0, b.getWidth(), b.getHeight()), borderRadius, borderRadius, p);
p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(b, 0, 0, p);
#1
1
The easy way would be your suggested solution, ie. drawing all circles with no alpha to a bitmap, then draw that bitmap to another one using the desired alpha. The hard way would be using blend modes, specifically PorterDuff.Mode in Android. An example can be found here.
简单的方法是你建议的解决方案,即。将所有没有alpha的圆绘制到位图,然后使用所需的alpha将该位图绘制到另一个位图。困难的方法是使用混合模式,特别是Android中的PorterDuff.Mode。这里有一个例子。
Also Check this http://softwyer.wordpress.com/2012/01/21/1009/
另请查看http://softwyer.wordpress.com/2012/01/21/1009/
An example
一个例子
Bitmap bitmap = Bitmap.createBitmap(b.getWidth(), b.getHeight(), b.getConfig());
Canvas canvas = new Canvas(bitmap);
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
p.setColor(Color.BLACK);
canvas.drawRoundRect(new RectF(0, 0, b.getWidth(), b.getHeight()), borderRadius, borderRadius, p);
p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(b, 0, 0, p);