Results 1 to 20 of 21

Thread: Using a 2d data array to create an image

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2008
    Posts
    74
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using a 2d data array to create an image

    Hi

    The data are just samples, each samples amplitude is to represent a pixels intensity in the final image . Essentially all I have is 2d array of data, from which I want to create an image for display. I was looking at QImage as a possible solution, as you can load the QImage buffer with data using scanline, but I couldnt get this to work.

    Thanks

  2. #2
    Join Date
    Oct 2008
    Posts
    74
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using a 2d data array to create an image

    Hi

    I suppose you could look at the problem this way. Consider a 2d array of chars of say 200 rows x 200 columns. Every element in a row has the same value, this value increases by one for every row. So for example each sample in the first row might have sample value of 1, the second row 2 and so on until we get to the final row which would have sample value of 200. If you created an image of this 2d array you would expect to see horizontal lines of increasing intensity (if we assume a grayscale image). How could I create such an image using QT and display this on a label/widget

    Thanks for your time

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Using a 2d data array to create an image

    then use QImage this class allows to access to pixels.

  4. #4
    Join Date
    Oct 2008
    Posts
    74
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using a 2d data array to create an image

    Yes, I have used QImage and loaded the buffer with my data. How di I subsequently display this QImage on a widget?

  5. #5
    Join Date
    Jul 2008
    Posts
    69
    Thanks
    9
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using a 2d data array to create an image

    I am also looking at similar problem (moving image )

    so in the designer create a Qlabel
    then access Qlabel ui.labelName->setQimage or something like that
    then modify the QImage using QPainter

    then update the

    I found an example in the demo to draw a ball with gradient
    Qt Code:
    1. pixmap = QPixmap(100, 100);
    2. pixmap.fill(Qt::transparent);
    3.  
    4. QRadialGradient gradient(50, 50, 50, 50, 50);
    5. gradient.setColorAt(0, QColor::fromRgbF(1, 0, 0, 1));
    6. gradient.setColorAt(1, QColor::fromRgbF(0, 0, 0, 0));
    7. QPainter painter(&pixmap);
    8. painter.fillRect(0, 0, 100, 100, gradient);
    9.  
    10. channelImage = pixmap.alphaChannel();
    11. update();
    To copy to clipboard, switch view to plain text mode 

    I am not sure yet if we can modify the Qpainter dot by dot
    This may help

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using a 2d data array to create an image

    Quote Originally Posted by dbrmik View Post
    Yes, I have used QImage and loaded the buffer with my data. How di I subsequently display this QImage on a widget?
    Transform it to QPixmap and display using QLabel.

  7. #7
    Join Date
    Jul 2008
    Posts
    69
    Thanks
    9
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using a 2d data array to create an image

    the problem seems to be how to modify the QPixmap having a set of coordinates X,Y
    is there any good example around?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using a 2d data array to create an image

    The pixmap is used to display data. QImage is used to manipulate data. Use QImage to change pixel colours and a pixmap created from it to display the image.

Similar Threads

  1. Replies: 2
    Last Post: 29th September 2008, 00:08
  2. Creating a Pixmap out of an array of data
    By toratora in forum Qt Programming
    Replies: 2
    Last Post: 5th June 2007, 19:00
  3. Help needed handling image data
    By toratora in forum General Programming
    Replies: 2
    Last Post: 11th May 2007, 09:24
  4. how to create resource fork & data fork
    By jyoti in forum General Discussion
    Replies: 4
    Last Post: 28th November 2006, 17:20
  5. How to create QPixmap from unsigned character array?
    By rashidbutt in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 18:25

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.