How convert QString to pixel array



  • Hello.
    I'm new user of this forum and also new in QT. Is it possible to convert for example one character or string to array where 0 means white field and 1 means black field? For example when I have character "a" saved as QString or char i would like to get following array:

    QString str = "a";
    //  HOW CONVERT str TO pixel representation array ???
    int array[9][6] = {                //"a" char array
          {0, 0, 0, 0, 0, 0},         //- - - - - -
          {0, 1, 1, 1, 1, 0},         //- * * * * -
          {1, 0, 0, 0, 0, 1},         //* - - - - *
          {0, 0, 0, 0, 0, 1},         //- - - - - *
          {0, 1, 1, 1, 1, 1},         //- * * * * *
          {1, 0, 0, 0, 0, 1},         //* - - - - *
          {1, 0, 0, 0, 1, 1},         //* - - - * *
          {0, 1, 1, 1, 0, 1},         //- * * * - *
          {0, 0, 0, 0, 0, 0},         //- - - - - -
    };
    

    Is there any way in QT for reach that goal ? I hope I describe my problem as clear ass possible and someone can help me with this?

    And very important thing size array must depend on selected font size, so if I choose for example 30 pt font, array shoule be appropriate bigger than 10 pt font.

    Thank You very much.
    Best regards.



  • It sounds to me like what you want to do is use a QPainter to paint your string into a QImage of depth 1 (QImage::Format_Mono). You will then be able to extract the bits into whatever format you want.



  • @Chris-Hennes many thanks for Your reply, it has appointed me the direction of further exploration.


Log in to reply