How to save text antialiasing on QImage?



  • If I draw text on QImage and then show it via QPainter on QWidget I get bad antialiasing compared to direct text drawing via QPainter.

    Here is simple code example:
    @#include <QApplication>
    #include <QtGui>

    class Widget : public QWidget
    {
    Q_OBJECT

    public:
    Widget(QWidget *parent = 0) : QWidget(parent)
    {
    m_img = QImage(QSize(200, 50), QImage::Format_ARGB32_Premultiplied);
    QPainter p(&m_img);
    p.setRenderHint(QPainter::Antialiasing);
    p.setRenderHint(QPainter::TextAntialiasing);
    p.fillRect(m_img.rect(), palette().color(QPalette::Active, QPalette::Window));
    p.setPen(palette().color(QPalette::Active, QPalette::Text));
    p.drawText(m_img.rect(), Qt::AlignCenter, "My Text 11~!");

        setFixedSize(200, 100);
    }
    void paintEvent(QPaintEvent *)
    {
        QPainter p(this);
        p.fillRect(rect(), palette().color(QPalette::Active, QPalette::Window));
        p.drawImage(0, 0, m_img);
        p.fillRect(0, 50, 200, 1, Qt::red);
        p.drawText(QRect(0, 50, 200, 50), Qt::AlignCenter, "My Text 11~!");
    }
    

    private:
    QImage m_img;
    };

    #include "main.moc"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    Widget w;
    w.show();
    return a.exec();
    }@

    Linux, KDE, Font: Verdana 11, Slight hinting, RGB subpixel rendering.

    Example (orig):
    !http://storage5.static.itmages.ru/i/14/0826/h_1409044667_3101927_6e9b0dfa23.png(100%)!
    Example (800% scale):
    !http://storage6.static.itmages.ru/i/14/0826/h_1409044714_6935247_ccc2136ebf.png(800%)!


Log in to reply
 

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