Create pixmap circle with smooth border

末鹿安然 提交于 2019-12-11 19:43:39

问题


How can i draw a circle with a smooth border on a pixmap?

The normal "sample" parameter in the config doesn't affect a pixmap.

EDIT:

 Pixmap ds = new Pixmap(width,height, Pixmap.Format.RGBA8888);
 ds.setColor(color);
 ds.fillCircle(ds.getWidth()/2, ds.getWidth()/2, (ds.getWidth()-20)/2);
 texture = new Texture(ds);

 ds.dispose();

The circle has a 200px radius.

A normal circle-shape created with the shaperenderer produces a perfectly smooth circle...


回答1:


The problem you have with the pixmap circle is, that it uses only one color, no gradients/transparency.

I guess you want to create the circle on the fly, since it can have a different radius each time? Otherwise create an image with the needed size. You need three different sizes? Do three different images, and so on.

If you need hundreds of different sizes, I would still create images, lets say for every tenth "step" and then pick the nearest one and scale.

If you can't use all of the above, it depends on how many circles you need to draw. If its only a "few" (maybe some selection circle, or similar) I would use the shape renderer (just measure how much time of your render loop it takes).

If that all is not a solution for you, you need to create a circle with the pixmap all by yourself, I'm no graphic guy, but I guess you could create a circle like you want in a paint program and see what color values it has at the edge so that you can mimic these values for your pixmap.

Note that a pixmap in itself is quite expensive, you should not use it for creating textures on the fly (do it in an initialization method) AND drawing single textures is quite bad, too, since a texture change causes a batch flush. So it might even be faster to use shape renderer if you don't merge them all into a texture atlas.



来源:https://stackoverflow.com/questions/33262697/create-pixmap-circle-with-smooth-border

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!