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. How to save text antialiasing on QImage?

How to save text antialiasing on QImage?

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.2k 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.
  • R Offline
    R Offline
    RazrFalcon
    wrote on last edited by
    #1

    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%)!

    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