QImage
需要最终显示为QLabel
中的缩略图。它在QByteArray
中序列化并通过网络发送。那么,我们可以将缩略图的QImage
转换为QByteArray
吗?基本上我想避免使用QImage::scale()
方法,因为它耗费了大量的CPU。
就像QImage
转换为QByteArray
一样,它将保存缩略图的数据。
答案 0 :(得分:0)
在这种情况下,您无法避免QImage :: scale。你为什么想要? 这是您如何将QImage保存到QByteArray的问题的答案。
QFile file(imagePath);
if (file.open(QIODevice::ReadOnly)) {
QByteArray bytes;
QImage img;
img = img.fromData(file.readAll());
img = img.scaled(200, 100, Qt::IgnoreAspectRatio, Qt::FastTransformation);
SetLabelImage(img);
QBuffer buffer(&bytes);
img.save(&buffer, "PNG");
}