Placing text in an Image object

≡放荡痞女 提交于 2019-12-13 11:08:30

问题


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.

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.

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.

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


回答1:


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

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.

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



来源:https://stackoverflow.com/questions/20559383/placing-text-in-an-image-object

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