Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Contert int matrix to QPixmap
QtWS25 Last Chance

Contert int matrix to QPixmap

Scheduled Pinned Locked Moved Unsolved General and Desktop
matrixqpixmapscene
2 Posts 2 Posters 1.5k 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.
  • AlvaroSA Offline
    AlvaroSA Offline
    AlvaroS
    wrote on last edited by
    #1

    hello everyone:

    First of all thanks a lot for reading this post and being able to help:

    I have a matrix like:

    int **matrix;

    with specific size.

    I would like to transform this matrix (a element is a pixel of the image) to a QPixmap to visualize the image in a scene.

    how can I do that¿?

    PD: From QImage to int** matrix the code looks like:

                matrix = new int *[img.width()];
    
                for(int i=0;i<img.width();++i)
                    matrix[i] = new int [img.height()];
    
                for(int i=0;i<img.width();++i){
                    for(int j=0;j<img.height();++j)
                        matrix[i][j] = QColor(img.pixel(i,j)).black() > 127 ? 0:1;
                }
    

    So the invert way to QPixmap?

    Thanks a lot.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! The way to convert your matrix to a QPixmap is to convert it to QImage first (e.g. using void QImage::setPixel(const QPoint &position, uint index_or_rgb)) and then convert the QImage to a QPixmap (using [static] QPixmap QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags = Qt::AutoColor)).

      1 Reply Last reply
      4

      • Login

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