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 conversion from 8 bit images to QImage::Format_Grayscale16
Forum Update on Monday, May 27th 2025

QImage conversion from 8 bit images to QImage::Format_Grayscale16

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 4 Posters 617 Views
  • 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 convert input 8 bit images to QImage::Format_Grayscale16.

    Here is the below code snippet
    QImage qimg("D:\image.png");
    QImage qimg24;

    qimg24 = qimg.convertToFormat(QImage::Format_Grayscale16);

    The input image is a 24 bit RGB888 png image.

    I get segmebntation fault if i run this. Wont the converttoformat convert it to grayscale8 and upscale the input image to 16 bit?

    Thanks
    Sachin

    Pablo J. RoginaP KroMignonK M 3 Replies Last reply
    0
    • SachinBhatS SachinBhat

      Hi,

      I wanted to convert input 8 bit images to QImage::Format_Grayscale16.

      Here is the below code snippet
      QImage qimg("D:\image.png");
      QImage qimg24;

      qimg24 = qimg.convertToFormat(QImage::Format_Grayscale16);

      The input image is a 24 bit RGB888 png image.

      I get segmebntation fault if i run this. Wont the converttoformat convert it to grayscale8 and upscale the input image to 16 bit?

      Thanks
      Sachin

      Pablo J. RoginaP Offline
      Pablo J. RoginaP Offline
      Pablo J. Rogina
      wrote on last edited by
      #2

      @SachinBhat said in QImage conversion from 8 bit images to QImage::Format_Grayscale16:

      I get segmebntation fault if i run this

      please provide the stack trace

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • SachinBhatS SachinBhat

        Hi,

        I wanted to convert input 8 bit images to QImage::Format_Grayscale16.

        Here is the below code snippet
        QImage qimg("D:\image.png");
        QImage qimg24;

        qimg24 = qimg.convertToFormat(QImage::Format_Grayscale16);

        The input image is a 24 bit RGB888 png image.

        I get segmebntation fault if i run this. Wont the converttoformat convert it to grayscale8 and upscale the input image to 16 bit?

        Thanks
        Sachin

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by KroMignon
        #3

        @SachinBhat said in QImage conversion from 8 bit images to QImage::Format_Grayscale16:

        QImage qimg("D:\image.png");
        QImage qimg24;
        qimg24 = qimg.convertToFormat(QImage::Format_Grayscale16);

        You have to check first if image loading was successful:

        QImage qimg("D:\\image.png");
        QImage qimg24;
        
        if(!img.isNull())
        {
            qimg24 = qimg.convertToFormat(QImage::Format_Grayscale16);
        }
        else
        {
            qDebug() << "Failed to load image!";
        }
        

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        1 Reply Last reply
        0
        • SachinBhatS SachinBhat

          Hi,

          I wanted to convert input 8 bit images to QImage::Format_Grayscale16.

          Here is the below code snippet
          QImage qimg("D:\image.png");
          QImage qimg24;

          qimg24 = qimg.convertToFormat(QImage::Format_Grayscale16);

          The input image is a 24 bit RGB888 png image.

          I get segmebntation fault if i run this. Wont the converttoformat convert it to grayscale8 and upscale the input image to 16 bit?

          Thanks
          Sachin

          M Offline
          M Offline
          mvuori
          wrote on last edited by
          #4

          I'd say your source image is nul because of :. Use double backslash ot forward slash.

          1 Reply Last reply
          0

          • Login

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