QImage - Determine the proper scale to fit a specific Byte Array Size



  • Hello,

    I have a function that take a QImage.
    I need to save this QImage in a QByteArray with a specific size.

    it can happen that this QImage is too big, so I need to "scaled" it.
    Is there anyway to determine the proper scaled to make for making the QImage fit a specific byte size ?

    Thanks in advance,



  • This dependes on the format, which most likely adds some kind of compression. The compression result is depend on the ordering of the pixels, which may be entirely different when pixels are differently aligned after scaling. This has a direct impact on the size in bytes.

    So, the conclusion is that there is some dependency (image contents, format, size) -> (size in bytes), but unless you aren't using an uncompressed format I wouldn't expect to be able to calculate the inversion of that function. This would be really complicated if even possible.



  • @cybercatalyst said:

    This dependes on the format, which most likely adds some kind of compression. The compression result is depend on the ordering of the pixels, which may be entirely different when pixels are differently aligned after scaling. This has a direct impact on the size in bytes.

    So, the conclusion is that there is some dependency (image contents, format, size) -> (size in bytes), but unless you aren't using an uncompressed format I wouldn't expect to be able to calculate the inversion of that function. This would be really complicated if even possible.

    Thanks for the answser.
    I think I will have to look for using BMP format. (https://support.microsoft.com/en-us/kb/132271)
    It is not the best optimization but it is the most quick calcul...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.