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.
  • A Offline
    A Offline
    AlvaroS
    wrote on 17 Jun 2016, 09:58 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 17 Jun 2016, 10:17 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

      2/2

      17 Jun 2016, 10:17

      • Login

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