一杯清酒邀明月
天下本无事,庸人扰之而烦耳。
 1   QString filename = QDir::homePath() + "/Desktop/TOF.png";
 2   QImage* img = new QImage;
 3   if(!(img->load(filename))) //加载图像
 4   {
 5     QMessageBox::information(this, tr("打开图像失败"), tr("打开图像失败!"));
 6         delete img;
 7         return;
 8   }
 9   //QPixmap->QByteArray
10   QPixmap pixmap = QPixmap::fromImage(*img);
11   QByteArray byteArray = QByteArray();
12   QBuffer buffer(&byteArray);
13   buffer.open(QIODevice::WriteOnly);
14   pixmap.save(&buffer,"png",0);
15   //QByteArray->QString
16   QString str2 = QString(byteArray.toBase64());
17   printf("%s", str2.toStdString()); 
18   //QString->QByteArray
19   QByteArray byteArray = QByteArray::fromBase64(str2.toLocal8Bit();
20   //QByteArray->QPixmap
21   QPixmap pix; 
22   pix.loadFromData(byteArray, "png");

 

posted on 2020-08-11 15:44  一杯清酒邀明月  阅读(1948)  评论(0编辑  收藏  举报