Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
250 views
in Technique[技术] by (71.8m points)

Placing text in an Image object

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...