Search code examples
c++qtdebugginggraphic

Draw a matrix of numbers as an image with C++


I have a quite specific question: I want to draw a matrix of numbers in a greyscale image. The higher the number the brighter the output. Is there a way to do that in a C++ programme without having dependencies to a graphic library like Qt?

I looked through some examples of ImageMagick, but I'm not sure how to implement its functions in C++.

Answer In case someone stumbles upon this question: a modified code of the example shown here was a handy and easy solution


Solution

  • It's hard without a library. SFML seems easy to use.

    EDIT

    Also you have 3 other questions hidden in your question:

    1- To save an image you can use sf::image::saveToFile

    2- To get brighter number for higher number: You need to normalize your numbers to [MinColorYouWant MaxColorYouWant] (for example: [128,255]). Thus the normalization value corresponding to each number will become the color of the number.

    3- SFML uses RGBA images by default. Just set the RGB channels equal to make it look greyscale.

    EDIT 2 : I've fixed the example normalization from [128,256] to [128,255].