我需要将已经创建的 QImage 编码为 QByteArray 以发送到套接字,并在另一端对其进行解码。
在服务器端,我正在尝试执行以下操作:
// The vector is mandatory. The class that creates the image line expects it.
QVector<unsigned char> msg;
QImage line(create_image_line(msg));
QByteArray ba((char*)line.bits(), line.numBytes());
for (int i = 0; i < ba.size(); ++i) {
msg.append(ba[i]);
}
send_msg(msg);
create_image_line 执行以下操作:
... handle the msg and get the image properties...
QImage img(pixels_, 1, QImage::Format_RGB32);
... set the values ...
return(img);
在客户端:
receive_msg(msg);
QByteArray ba;
for (int i = 0; i < msg.size(); ++i) {
ba.append(msg[i]);
}
QImage line(LINE_WIDTH, 1, QImage::Format_RGB32);
line.fromData(ba);
出了点问题,图像显示有很多噪点(我知道问题出在此转换中,由于另一个成功的测试)。
我想知道问题出在哪里。
Rgds。