将文本放在Image对象中 [英] Placing text in an Image object

查看:128
本文介绍了将文本放在Image对象中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SFML 2.1并且有一个Image,其中有一些我想要编号的对象,即我有一组原点坐标,所以我会将数字放在那里。

I am using SFML 2.1 and have an Image with some objects that I would like to number, i.e. I have a set of origin coordinates for each of them so I would place the number there.

然而,我似乎无法找到一个好方法:最相关的函数似乎是 Image :: copy() 在图像中放置一个矩形。要使用它,我必须创建一个数字地图图像,然后对连续的数字进行偏移,这看起来繁琐,繁琐和不可靠,因为具有太多对象的图像最终会用完数字。

However, I can't seem to find a good way to do this: the most relevant function seems to be Image::copy() which places a rectangle in the image. To use that, I would have to create a number map image and then do offsets for successive numbers, which seems tedious, cumbersome and unreliable, as an image with too many objects would eventually run out of numbers.

我还想到了可以想象使用 RenderWindow 对象并将图像和数字一起打印为 sf :: Text 具有正确坐标的对象,但API似乎没有提供将窗口内容保存到图像的方法。

I also thought of conceivably using a RenderWindow object and printing the Image along with numbers as sf::Text objects with the right coordinates, but the API does not seem to provide a way to save the contents of the window to an image.

所以问题是:是否有一种简单的方法可以在 Image 对象中放置数字(一般文字)?

So the question is: is there a straightforward way to place numbers (text in general) in an Image object?

推荐答案

您的问题相当不清楚,因此我认为负面评价。

Your question is rather unclear, thus I guess the negative ratings.

如果要渲染文本,只需将 sf :: Text 对象绘制为 sf :: RenderWindow 对象。如果要重用最终结果,可以使用 sf :: RenderTexture 切换 sf :: RenderWindow 。如果你想操纵单个像素,你必须使用 sf :: Image ,但请记住从图像到纹理的转换是一个缓慢的过程,所以如果没有必要,请不要这样做。

If you want to render text, you can simply draw an sf::Text object to an sf::RenderWindow object. If you want to reuse the final result you can switch out the sf::RenderWindow with a sf::RenderTexture. If you want to manipulate single pixels, you'll have to go with an sf::Image, but keep in mind the conversion from image to texture is a slow process, so don't do it, if it isn't necessary.

见官方文档教程如何使用SFML。

See the official documentation and tutorials on how to work with SFML.

这篇关于将文本放在Image对象中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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