Compressing and Serializing QImage over the Network and knowing compressed size in advance

StackOverflow https://stackoverflow.com/questions/5828807

  •  27-10-2019
  •  | 
  •  

Question

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.

Was it helpful?

Solution

Would it help you to use the QImageWriter to write into a QBuffer? This way you would avoid the disk overhead and you can access the QByteArray to get its size and data to push that directly into your network stream. So you would have to encode the JPEG still only once.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top