Results 1 to 4 of 4

Thread: QPixmap import/export

  1. #1
    Join Date
    May 2007
    Location
    Konstanz, Germany
    Posts
    2
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question QPixmap import/export

    Hello everybody,

    i have a problem using the QPixmap class in Qt. I want to change QPixmaps in char* and vice versa because my framegrabber stores images in that way.

    Example:
    myClass::myMethod(QPixmap *myQPixmap)
    {
    // create imagepointer to image in framebuffer
    mem0[0] = (char*) Fg_getImagePtrEx(fg,1,dma_no,pmem0);

    // create test images in framebuffer, black to white gradient
    for(int i=0;i<width*height;i++)
    {
    mem0[0][i] = i;
    }
    }


    In this method i want to use the given myQPixmap as source instead of the generated test image. How can i do that?

    Many thanks,
    Matthias

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap import/export

    convert the QPixmap to QImage, and use QImage::bits() to access the raw data.
    And PLEASE, use code tags, and not that hideous blue color.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    Matthias (1st June 2007)

  4. #3
    Join Date
    May 2007
    Location
    Konstanz, Germany
    Posts
    2
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap import/export

    Quote Originally Posted by high_flyer View Post
    convert the QPixmap to QImage, and use QImage::bits() to access the raw data.
    And PLEASE, use code tags, and not that hideous blue color.
    Thank you, i converted the QPixmap to QImage and tried copy the Qimage to the raw data.

    Qt Code:
    1. // my raw data
    2. unsigned char *myField = (unsigned char*) Fg_getImagePtrEx(fg,1,dma_no,pmem0);
    3.  
    4. // converting QPixmap to QImage
    5. QImage testImage = testPixmap->convertToImage ();
    6.  
    7. // fill the Field with data from QImage (I think there is an Error)
    8. myField = testImage.bits();
    To copy to clipboard, switch view to plain text mode 

    Do i only copy one pixel? Whats wrong?

  5. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QPixmap import/export

    Do i only copy one pixel? Whats wrong?
    you are doing it the other way around...
    You said you want to
    to change QPixmaps in char* and vice versa
    Then:
    Qt Code:
    1. unsigned char *myField = (unsigned char*) Fg_getImagePtrEx(fg,1,dma_no,pmem0);
    2. //Pixmap to unsigned char*
    3. QPixmap *pixmap = new QPixmap("image.png");
    4. unsigned char *buff = pixmap->convertToImage().bits(); //access the raw image data
    5. //unsigned char to Pixmap
    6. pixmap->loadFromData(myField,imageSize);
    To copy to clipboard, switch view to plain text mode 

    Have a look at QPixmap and QImage.
    Last edited by high_flyer; 1st June 2007 at 09:34.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. The following user says thank you to high_flyer for this useful post:

    Matthias (1st June 2007)

Similar Threads

  1. Convert QPixmap to QByteArray ?
    By probine in forum Qt Programming
    Replies: 5
    Last Post: 13th March 2014, 08:23
  2. QPixmap into QTextBrowser
    By xgoan in forum Qt Programming
    Replies: 6
    Last Post: 3rd November 2006, 13:05
  3. QPixmap -> HICON trouble.
    By krivenok in forum Qt Programming
    Replies: 1
    Last Post: 11th August 2006, 15:51
  4. Loading a custom image into a QPixmap
    By KShots in forum Qt Programming
    Replies: 12
    Last Post: 5th August 2006, 00:16
  5. QPixmap and HBITMAP
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2006, 16:24

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.