QString fileName = QFileDialog::getOpenFileName(this,"打开文件",QString(),tr("Image(*.jpg *.gif *.png)"));
QImage image;
if(!image.load(fileName)){
qDebug()<<"加载图片失败";
return;
}
ui->label->setPixmap(QPixmap::fromImage(image).scaled(ui->label->width(),ui->label->height()));
QByteArray pixArray;
QBuffer buffer(&pixArray);
buffer.open(QIODevice::ReadWrite);//image不能为空,必须先将图片加载到image中
image.save(&buffer,"png");
将图片转为QByteArray进行传输
最新推荐文章于 2023-08-02 18:25:37 发布