c++imageppm

TEXT to IMAGE converter in C++ without using any libraries


I am currently working on a coding task in which i am required to create a program which takes a string as an input and return a ".ppm" image of that text. I can't figure out a way as to how i should go about solving this problem without using an external library (or maybe with the most basic c++ library).

What i am thinking of doing ...

" Create a 2d array for a every letter in the alphabet and then select and append those characters which are in the string." But this approach seems rather inelegent.

Any suggestion would of great help.


Solution

  • What you describe is basically the only way to do this. You won't get around defining some kind of font that describes the appearance of each character.

    Bitmap fonts as you describe are one way to do this. (I guess you don't really mean 2x2 but MxN where M and N are some larger integers.)

    Another possibility is to use vector fonts where you only describe the strokes or the outlines of the letters by a sequence of curves. These typically require less memory to store a letter and, what's more important, they are resolution independent. However at some point you still need to convert these vector descriptions into a bitmap.