Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QImage scaledtoHeight does not work for QImage::Format_Grayscale16
Forum Updated to NodeBB v4.3 + New Features

QImage scaledtoHeight does not work for QImage::Format_Grayscale16

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
5 Posts 3 Posters 700 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SachinBhatS Offline
    SachinBhatS Offline
    SachinBhat
    wrote on last edited by
    #1

    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?

    Thanks
    Sachin

    1 Reply Last reply
    0
    • SachinBhatS Offline
      SachinBhatS Offline
      SachinBhat
      wrote on last edited by
      #2

      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?

      Thanks
      Sachin

      jsulmJ 1 Reply Last reply
      0
      • SachinBhatS SachinBhat

        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?

        Thanks
        Sachin

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

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

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • SachinBhatS Offline
          SachinBhatS Offline
          SachinBhat
          wrote on last edited by kshegunov
          #4

          Hi,
          @jsulm Thank you for your reply.

          Below is the code snippet:

             QImage img("file_location");
          
          #if IMG_DEBUG
              writer1.write(img);
          #endif
              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);
              }
          
              if(img.isNull())
                  return NULL;
          
              int scaleHeight = DIV_ROUND(PTN_IMG_HEIGHT * img.height(),m_ptnHeight);
          
              scaledImage = img.scaledToHeight(scaleHeight);
          

          I get improper output.

          4f527f8b-8d95-4111-8368-f934481c3087-image.png
          Left is the input, right is the output image

          I get proper outputs for other formats

          Thanks
          Sachin

          [Edit: Added code tags ~kshegunov]

          kshegunovK 1 Reply Last reply
          0
          • SachinBhatS SachinBhat

            Hi,
            @jsulm Thank you for your reply.

            Below is the code snippet:

               QImage img("file_location");
            
            #if IMG_DEBUG
                writer1.write(img);
            #endif
                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);
                }
            
                if(img.isNull())
                    return NULL;
            
                int scaleHeight = DIV_ROUND(PTN_IMG_HEIGHT * img.height(),m_ptnHeight);
            
                scaledImage = img.scaledToHeight(scaleHeight);
            

            I get improper output.

            4f527f8b-8d95-4111-8368-f934481c3087-image.png
            Left is the input, right is the output image

            I get proper outputs for other formats

            Thanks
            Sachin

            [Edit: Added code tags ~kshegunov]

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #5

            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).

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved