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");