QImage scaledtoHeight does not work for QImage::Format_Grayscale16

  • Hi,

    I wanted to scale the input image of format QImage::Format_Grayscale16. But the output image post transformation is garbage. Could anyone please provide a way to scale my images with the help of an inbuilt function?


  • Hi,

    I can provide more information if I am not clear with the problem?

    The scaletoheight() uses transformation of images for scaling which I do not have any idea of implementation. I cannot convert the format to a format where the scaling is possible either. Or is there a way?


  • Lifetime Qt Champion

    @SachinBhat Please show your code where you scale the image...

  • Hi,
    @jsulm Thank you for your reply.

    Below is the code snippet:

       QImage img("file_location");
    #if IMG_DEBUG
        if (img.format() >= QImage::Format_RGBX64)
            int width = DIV_ROUND(m_ptnWidth * PTN_IMG_HEIGHT, m_ptnHeight);
            delete m_ptnImageCache[cacheIndex].img;
            m_ptnImageCache[cacheIndex].img = new QImage(width, PTN_IMG_HEIGHT, QImage::Format_Grayscale16);
            return NULL;
        int scaleHeight = DIV_ROUND(PTN_IMG_HEIGHT * img.height(),m_ptnHeight);
        scaledImage = img.scaledToHeight(scaleHeight);

    I get improper output.

    Left is the input, right is the output image

    I get proper outputs for other formats


    [Edit: Added code tags ~kshegunov]

  • Moderators

    It's possible this is a bug, seems that the pixel data alignment is broken for some reason. Could you prepare a very simple self-contained project (along with the test image) and upload it somewhere? Please strip the irrelevant code if you decide to do so (like the m_ptnImageCache).

Log in to reply