I am sending Several MessagePacket and ScreenPacket over the network. but all this packets are followed by a CommonHeaderPacket which Tells the type, size, id, time, and checksum of the upcoming packet. So I need to know the size of Packet before sending.
ScreenPacket has a _image:QImage (jpeg) which will also be compressed and serialized over the network. I can do this through QImageWriter while sending this over the socket. But before sending the ScreenPacket I need to send the CommonHeaderPacket that includes the size. so how can I know the size in advance ? as QImage has no setQuality() or setCompression() method.
I dont want to write it in a temporary stream to know the size in advance. so what else could be the way to know the size in advance.
Summary
QImage has no setCompression or setQuality Method. QImageWriter has. But I need to know the ByteSize before writing. and byte size depends on the compression and quality.
e.g. I need an QImage to be saved into another Persistent storable Object with a Change in Quality, Compression. without Disk Overhead.
Would it help you to use the
QImageWriterto write into aQBuffer? This way you would avoid the disk overhead and you can access theQByteArrayto get its size and data to push that directly into your network stream. So you would have to encode the JPEG still only once.