send a picture of the code :
QByteArray buffer (6 +3 * image-> width (), 0);
QDataStream stream (& buffer, QIODevice :: WriteOnly);
stream.setVersion (QDataStream :: Qt_4_6);
stream << (quint16) image-> width () << (quint16) image-> height ();
quint16 y = qrand ()% image-> height ();
stream << y;
for (int x = 0; x
{
QRgb rgb = image-> pixel (x, y);
stream << (quint8) qRed (rgb) << (quint8) qGreen (rgb) << (quint8) qBlue (rgb);
}
socket-> writeDatagram (buffer.data (), buffer.size (), QHostAddress :: Broadcast, 8888);
receive a picture of the code :
while (socket-> hasPendingDatagrams ())
{
QByteArray buffer (socket-> pendingDatagramSize (), 0);
socket-> readDatagram (buffer.data (), buffer.size ());
QDataStream stream (buffer);
stream.setVersion (QDataStream :: Qt_4_6);
quint16 width, height, y;
stream >> width >> height >> y;
if (! image)
image = new QImage (width, height, QImage :: Format_RGB32);
else if (image-> width ()! = width | | image-> height ()! = height)
{
delete image;
image = new QImage (width, height, QImage :: Format_RGB32);
}
for (int x = 0; x
quint8 red, green, blue;
stream >> red >> green >> blue;
ui-> textEdit-> append ("ddd");
image-> setPixel (x, y, qRgb (red, green, blue)) ;
}
}
displayed after receiving
for a long time did not find out what is wrong , please help me ah
------ Solution ------------------------------------ --------
a picture , a large amount of data is not where to go
outer For loop can make a break , check the value of the byte array is valid ?
In addition , QImage has a function can be directly extracted image data array of char , you look at two functions :
int QImage :: byteCount () / / returns the total number of bytes of image data
uchar * QImage :: bits () / / / / returns the first address of the image data
With these two parameters can be sent directly :
socket-> writeDatagram (image-> bits (), image-> byteCount (), QHostAddress :: Broadcast, 8888);
recipient can use this byte array directly construct a picture :
QImage (uchar * data, int width, int height, int bytesPerLine, Format format)
image width and format of information can also be sent together with the image data to the client together with the analytical
------ eference ----------------- ----------------------
for (int x = 0; x
{
QRgb rgb = image-> pixel (x, y);
stream << (quint8) qRed (rgb) << (quint8) qGreen (rgb) << (quint8) qBlue (rgb);
}
random height on the image to obtain partial image network transmission ?
code above looks like you just take a picture of a row of data ( image height is 1 ) , should quint16 y = qrand ()% image-> height ();
cycle also got ah such : for (int i = 0; i
------ eference --------------------------------------- < br> according to your prompt , modify the following :
for (int y = 0; y
{
for (int x = 0; x
{
QRgb rgb = image-> pixel (x, y);
stream << (quint8) qRed (rgb) << (quint8) qGreen (rgb) << (quint8) qBlue (rgb);
}
}
but the received data stream, have not received any data , data may be too large ?
------ eference --------------------------------------- < br> the problem is resolved, the original image can not be a one-time all the data sent to the past, QByteArray will exceed the maximum capacity of the transmission line by line, so I have no problem
------ eference ----- ----------------------------------
need to be able to read
------ eference ---------------------------------------
you put quint16 to quint32 ; OK, try it as soon as possible , I encountered the same problem , resolved
------ eference -------------------- -------------------
how time and again pass it
没有评论:
发表评论