Important: Please read the Qt Code of Conduct -

How to get the bitmap from an Qimage

  • Hi guys,

    I need to have the array with the bits from a QImage. I thougth I could do something with the
    QImage myImage;
    QByteArray ba;
    QBuffer buffer(&ba);;, "PNG"); // writes image into ba in PNG format@

    I need that array because then I can have a second array from an image to transform the 2 images and show them back on the screen.

    For example got a background image + a foreground image and then I could merge them that you see the background image only where the foreground image has nothing to show.

    Kind regards,

  • QImage in memory is practically a two-dimensional array of pixels. See the pixel() and setPixel() methods. The only property of a pixel is a color value.

  • Oké thanks. I tried the pixel method it gives me this 4293852159 color value back, but I can't do any methods to get the rgb value or the hex value. Do I need to convert this to a QColor first or how?

  • QRgb is a 32bit (I think) integer value holding the 4 color elements including alpha. You can manipulate the integer values if you are into such things, or load it into a QColor (setRgba()).

  • Hi,

    If I understand you right, you want to composite images. You can use "QPainter::setCompositionMode":

Log in to reply