Results 1 to 6 of 6

Thread: QImage Issue

  1. #1
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question QImage Issue

    Hi All,
    I m using QT 4.2.2 on my Intel Mac.
    I have a unsigned char * buffer.....
    unsigned char *pBuff= new unsigned char[SizeToRead];

    I gave some bytes read from the harddisk to construct a image and I m using the following to construct a image from the above Buffer

    QImage::QImage ( uchar * data, int width, int height, Format format )

    But Actually I donot know the format of the image so I can not able to give the parameter Format value.

    So How can I know the format of the image from the Bytes I have read or there is another method to construct an image from uchar * buffer.

    Thanks.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QImage Issue

    Will this thread be useful to you ??

  3. #3
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Re: QImage Issue

    I m usng the following to create image from the uchar *......

    bool QImage::loadFromData ( const uchar * data, int len, const char * format = 0 )

    When i check this return vaue it is coming out to be true and when I m checking that....

    if(image.isNull()) then it is returning false that is it is creating image but when i m setting that image in the pixmap using..

    image=image.scaled(100,100); QPixmap pixmap;
    pixmap.fromImage(image,Qt::AutoColor);

    and showing that in the QListWidget it is not showing the image I m using the following code

    listWidget->setViewMode(QListView::IconMode);
    QListWidgetItem *LWidgetItem=new QListWidgetItem(pixmap,"HI",listWidget,0);

    But it is showing the text HI not the image.

    If any body knows why then plz help me again.

    Thanks.

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

    Default Re: QImage Issue

    QPixmap::fromImage() is a static method returning the pixmap:

    Qt Code:
    1. QImage img;
    2. QPixmap pix = QPixmap::fromImage(img);
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QImage Issue

    Hi,

    Are you sure that you are not destructing the memory data buffer?
    In the QImage contructor you can read this:

    "The buffer must remain valid throughout the life of the QImage. The image does not delete the buffer at destruction."

    So, I think that you have to mantain the data buffer into memory. Try to execute "bool bOK = image.isNull();" just after "loadFromData" call.
    Òscar Llarch i Galán

  6. #6
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QImage Issue

    Thanks to all of you.
    Now I m able to do that.

Similar Threads

  1. [Qt4] How to load Url image into QImage?
    By Gonzalez in forum Qt Programming
    Replies: 6
    Last Post: 13th October 2014, 10:10
  2. Creating a QImage from uchar* data
    By forrestfsu in forum Qt Programming
    Replies: 6
    Last Post: 8th February 2007, 15:21
  3. QImage constructor
    By Lele in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2007, 12:06
  4. Replies: 5
    Last Post: 22nd September 2006, 08:04
  5. QPainter and QImage
    By beerkg in forum Newbie
    Replies: 3
    Last Post: 7th September 2006, 14:48

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.