Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPainter drawText on a QImage: Wrong text color???!!!

QPainter drawText on a QImage: Wrong text color???!!!

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 11.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zff518
    wrote on last edited by
    #1

    @
    QImage tmpImage = rgb32.convertToFormat(QImage::Format_ARGB32_Premultiplied);

    QPainter painter;
    painter.begin(&tmpImage);
    painter.setPen(fontColor); // The font color comes from user select on a QColorDialog
    painter.setFont(QFont("Chicago", fontSize)); // The font size comes from user input
    painter.setCompositionMode(QPainter::CompositionMode_Source);

    painter.drawText(penPos.x(), penPos.y(), QString::number(num)); // Draw a number on the image

    painter.end();

    rgb32 = tmpImage.convertToFormat(QImage::Format_RGB32);
    @

    Hello everyone :)

    I want to draw a number on a QImage (a series of QImages) fetched from a video sequence. I used the code above.

    The problem is, the text color, which comes from user select, is not printed correctly. For example, the fontColor is Qt::red, but a blue text were printed.

    I also tried other compositionmode, such as
    @painter.setCompositionMode(QPainter::CompositionMode_SourceOver);@
    or
    @painter.setCompositionMode(QPainter::CompositionMode_Clear);@

    but nothing changed.

    Can anybody help me?

    Thanks in advanced.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      RazrFalcon
      wrote on last edited by
      #2
      1. Did you try to draw text on usual image loaded to tmpImage?
      2. Why you use Format_ARGB32_Premultiplied? Video didn't has alpha layer.
      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved