2016-11-06 2 views
0

Alles was ich brauche ist einfach (Q) string es als eingebettetes Bild zu setzen wie:Irgendwelche Ideen, wie QR-Daten in PNG-Bild zu kodieren?

<img src="data:image/png;base64,iVBORw..."> 

Ich benutze: #include <qrencode.h> (Linux -> apt-get install libqrencode-dev)

Dies ist mein Code:

QRcode *qr=QRcode_encodeString(QString("my test string").toStdString().c_str(), 1, QR_ECLEVEL_L, QR_MODE_8,1); 
QByteArray *ba = new QByteArray(); 
for (unsigned int y=0; y<qr->width;y++) 
{ 
    int yy=y*qr->width; 
    for (unsigned int x=0; x<qr->width;x++) 
    { 
     int xx=yy+x; 
     const unsigned char b=qr->data[xx]; 

     ///WHAT TO DO NOW??? IS IT CORRECT? 
     ba->push_back(b); 
     qDebug()<<"Char "<<b; 
     if(b &0x01) 
     { 
     qDebug()<<"Point +++"; 
     } 
    } 
} 

qDebug()<<ba->toBase64(); 

Irgendwelche Ideen, wie qr->data in ein png Bild zu kodieren?

Antwort

0

Ich habe es geschafft! :) Erste Version, ohne

#include<QString> 
    #include<QDebug> 
    #include<QByteArray> 
    #include<QBuffer> 
    #include<QImage> 
    #include<QImageWriter> 
    #include<QPixmap> 
    #include<QPainter> 
    #include<QColor> 
    #include<QPointF> 
    #include<QRectF> 



    //ustawiam kolory 
    QColor bialy = Qt::white; 
    QColor czarny = Qt::black; 

//PNG  
     QByteArray ImageAsByteArray; 
     QBuffer ImageBuffer(&ImageAsByteArray); 
     ImageBuffer.open(QIODevice::WriteOnly); 




    QRcode *qr=QRcode_encodeString(QString("afya.pl").toStdString().c_str(), 1, QR_ECLEVEL_L, QR_MODE_8,1); 

    QPixmap p(qr->width,qr->width); 
    QPainter pa; 
    pa.begin(&p); 
    pa.setRenderHints(QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing |QPainter::TextAntialiasing| QPainter::Antialiasing); 
    pa.setPen(bialy); 
    pa.setBrush(bialy); 
    //czyścimy tło 
    QPointF a=QPointF(0.0,0.0); 
    QPointF b=QPointF(p.width(),p.height()); 
    pa.drawRect(QRectF(a,b)); 


    pa.setPen(czarny); 

    for (unsigned int y=0; y<qr->width;y++) 
    { 
     int yy=y*qr->width; 
     for (unsigned int x=0; x<qr->width;x++) 
     { 
     int xx=yy+x; 
     const unsigned char b=qr->data[xx]; 

     if(b &0x01){ 
    a=QPointF(y,x); 
    pa.drawPoint(a); 
     } 
     } 


    } 
    p.save(&ImageBuffer,"PNG"); 


    qDebug()<<ImageAsByteArray.toBase64(); 
    } 
+1

einzelnen Pixel einstellen Skalierung ist auch einfacher, wenn Sie 'QImage' anstelle fof' QPixmap', also mit 'QImage :: setPixel()' statt mit 'QPainter :: drawPoint() '. Abhängig vom Format von 'qr-> data' könnte es sogar möglich sein, dies direkt in ein' QImage' umzuwandeln –

Verwandte Themen