创建具有平滑边框的像素图圆 [英] Create pixmap circle with smooth border

查看:166
本文介绍了创建具有平滑边框的像素图圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在像素图上绘制带有平滑边框的圆?

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.

 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();

该圆的半径为200px.

The circle has a 200px radius.

使用shaperenderer创建的普通圆形会产生一个完美平滑的圆形...

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

推荐答案

像素图圆的问题在于,它仅使用一种颜色,没有渐变/透明度.

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.

这篇关于创建具有平滑边框的像素图圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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