Results 1 to 13 of 13

Thread: QImageIOPlugin, support for new image format.

  1. #1
    Join Date
    Nov 2008
    Location
    Bangalore, India
    Posts
    21
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Symbian S60

    Thumbs up QImageIOPlugin, support for new image format.

    Hi,

    We have created a plugin to support a new imageformat.
    When i load the new image, it talks to the corresponding imagerenderer through plugin. and returns a qimage.
    But I am not able to pass the size for this qimage to the plugin.
    How to do it ?

    or atleast, how to specify the new imageformat in the constructor with the size.
    I did not find any QImage constructor for the same .

    If I do,

    QImage image(200, 200, QImage::Format_Invalid);
    image.load("c:\\data\\sample.abc","abc")

    it is not taking size (200, 200).
    also, how in the constructor above how I can specify the new image format ??

    Please help me in solving this problem.

  2. #2
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QImageIOPlugin, support for new image format.

    QImage::load() doesn't scale the image. It is supposed to return an image the size that is presumably specified in the file.
    Also, Qt will know to use your plugin when encountering a ".abc" file if your plugin class reimplements QImageIOPlugin::keys() to return "abc".

  3. #3
    Join Date
    Nov 2008
    Location
    Bangalore, India
    Posts
    21
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Symbian S60

    Thumbs up Re: QImageIOPlugin, support for new image format.


    QImage image(200, 200, QImage::Format_Invalid);
    image.load("c:\\data\\sample.abc","abc")


    ok,

    In the plugin I have a QSize abcSize, and the image created from sample.abc is of size abcSize. So, how to pass the size (to the plugin) ?
    In the aboe code, image size is abcSize, not (200,200). I want a QImage to be created of size (200,200) or any other size that we pass.

  4. #4
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QImageIOPlugin, support for new image format.

    Well you could always use
    Qt Code:
    1. image.scale();
    To copy to clipboard, switch view to plain text mode 

    If you want more control, you should use QImageReader.

  5. #5
    Join Date
    Nov 2008
    Location
    Bangalore, India
    Posts
    21
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Symbian S60

    Thumbs up Re: QImageIOPlugin, support for new image format.

    Thank you,
    QImageReader worked for me.

    But, if I use image.scale() ,, then it'll scale the original image to the vale passed in scale().

    So, is there anything similar; to create a QIcon of specific size from a file?
    Last edited by suneel1310; 4th March 2009 at 10:25.

  6. #6
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QImageIOPlugin, support for new image format.

    Have a look at QImageIOHandler::ImageOption, in specific QImageIOHandler::ScaledSize and QImageIOHandler::supportsOption().

    Qt Code:
    1. class MyImageHandler : public QImageIOHandler
    2. {
    3. ...
    4. bool supportsOption ( ImageOption option )
    5. {
    6. if(option==ScaledSize)
    7. return true;
    8. ...
    9. }
    10. bool read ( QImage * image )
    11. {
    12. QSize scaledSize = option(ScaledSize).toSize();
    13. ...
    14. }
    15. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. QImage icon(64, 64, QImage::Format_RGB32);
    2. QImageReader reader("XXX.abc");
    3. reader.setScaledSize(QSize(64,64);
    4. if (reader.read(&icon)) {
    5. // Display icon
    6. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Nov 2008
    Location
    Bangalore, India
    Posts
    21
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Symbian S60

    Default Re: QImageIOPlugin, support for new image format.

    Thank you.
    QImage Reader solved my problem

    Now, Is there anything similar in QPixmap?? like QImageReader for QImage.
    Or, we should create QImage first and then converting it to QPixmap?

  8. #8
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QImageIOPlugin, support for new image format.

    Create a QImage and then convert it.

  9. #9
    Join Date
    Nov 2008
    Location
    Bangalore, India
    Posts
    21
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Symbian S60

    Default Re: QImageIOPlugin, support for new image format.

    But, converting from QImage to Qpixmap is expensive, interms of performance.
    So, isn't there any other approach? which is good in performance.

  10. #10
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QImageIOPlugin, support for new image format.

    It might be expensive, but not necessarily. On windows each QPixmap internally holds a QImage, so it is virtually for free. Anyway it is unavoidable. You first need to load the image from the hard drive into RAM buffer. You do this by loading a Qimage. You then want to transfer the image to your screen buffer(be it an X-Server, or an OpenGL texture). You do this by converting the QImage to a QPixmap.

    It is only expensive in the sense that it is wasteful to convert back and forth within a paintEvent(). You still have to do the conversion once, so that subsequent manipulations of the QPixmap(rotations, scaling etc) make best use of the underlying rendering system.

    I hope that the answer makes sense to you.

  11. The following user says thank you to spud for this useful post:

    talk2amulya (6th March 2009)

  12. #11
    Join Date
    Nov 2008
    Location
    Bangalore, India
    Posts
    21
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Symbian S60

    Default Re: QImageIOPlugin, support for new image format.

    Yes,
    Thanks a lot for that info.
    It really helped me.

  13. #12
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QImageIOPlugin, support for new image format.

    spud: that was really helpful info. just one question. is it QImage that contains a QPixmap or a QPixmap that contains a QImage...in windows..

  14. #13
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QImageIOPlugin, support for new image format.

    QPixmap contains a QImage.

Similar Threads

  1. get QImage object from buffer
    By Sheng in forum Qt Programming
    Replies: 2
    Last Post: 21st September 2012, 02:03
  2. Qt 4.4.3 commercial on Kubuntu 8.10
    By Micawber in forum Installation and Deployment
    Replies: 5
    Last Post: 17th February 2010, 01:02
  3. Qt-4.4.0 installation error in linux
    By babu198649 in forum Installation and Deployment
    Replies: 4
    Last Post: 27th May 2008, 14:35
  4. Some very weird compilation warnings
    By MarkoSan in forum Qt Programming
    Replies: 21
    Last Post: 23rd January 2008, 16: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.