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



  • @
    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. 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.

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.