Esempio n. 1
0
void QAlphaPaintEnginePrivate::drawAlphaImage(const QRectF &rect)
{
    Q_Q(QAlphaPaintEngine);

    qreal dpiX = qMax(m_pdev->logicalDpiX(), 300);
    qreal dpiY = qMax(m_pdev->logicalDpiY(), 300);
    qreal xscale = (dpiX / m_pdev->logicalDpiX());
    qreal yscale = (dpiY / m_pdev->logicalDpiY());

    QTransform picscale;
    picscale.scale(xscale, yscale);

    const int tileSize = 2048;
    QSize size((int(rect.width() * xscale)), int(rect.height() * yscale));
    int divw = (size.width() / tileSize);
    int divh = (size.height() / tileSize);
    divw += 1;
    divh += 1;

    int incx = int(rect.width() / divw);
    int incy = int(rect.height() / divh);

    for (int y=0; y<divh; ++y) {
        int ypos = int((incy * y) + rect.y());
        int height = int((y == (divh - 1)) ? (rect.height() - (incy * y)) : incy) + 1;

        for (int x=0; x<divw; ++x) {
            int xpos = int((incx * x) + rect.x());
            int width = int((x == (divw - 1)) ? (rect.width() - (incx * x)) : incx) + 1;

            QSize imgsize((int)(width * xscale), (int)(height * yscale));
            QImage img(imgsize, QImage::Format_RGB32);
            img.fill(0xffffffff);

            QPainter imgpainter(&img);
            imgpainter.setTransform(picscale);
            QPointF picpos(qreal(-xpos), qreal(-ypos));
            imgpainter.drawPicture(picpos, *m_pic);
            imgpainter.end();

            q->painter()->setTransform(QTransform());
            QRect r(xpos, ypos, width, height);
            q->painter()->drawImage(r, img);
        }
    }
}
Esempio n. 2
0
int main(int argc,char *argv[])
{
    QApplication a(argc,argv);
    QDir dir;
    QStringList filters;
    filters<<"*.png"<<"*.PNG";
    dir.setNameFilters(filters);
    dir.setPath(".");
    QFileInfoList list = dir.entryInfoList();
    QFileInfo k;
    QImage image(46,list.size()*46,QImage::Format_RGB32);
    QPainter imgpainter(&image);
    QImage bk(":/bk/bk.png");
    bk=bk.scaled(46,46);
    for(int i=0;i<list.size();++i){
        QImage im;
        k=list[i];
        im.load(k.fileName());
        QImage temp=im.scaled(40,40);
        QImage paintDevice=bk;
        QPainter painter(&paintDevice);
        QPen pen;
        pen.setColor(QColor("#a5a9d7"));
        pen.setWidth(1);
        painter.setPen(pen);

        painter.drawRoundedRect(0,0,45,45,2,2);
        painter.drawImage(3,3,temp);
        painter.end();
        qreal y=46.0*i;
        imgpainter.save();
        imgpainter.translate(0.0,y);
        imgpainter.drawImage(0,0,paintDevice);
        imgpainter.restore();
    }
    image.save("pattern.png","PNG");
    QMessageBox::information(0,"Notify","Image Composed Complete");
    exit(0);
    return a.exec();
}