PDA

View Full Version : QImageIOPlugin, support for new image format.



suneel1310
3rd March 2009, 11:20
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.

spud
3rd March 2009, 12:02
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".

suneel1310
4th March 2009, 03:56
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.

spud
4th March 2009, 06:50
Well you could always use
image.scale();

If you want more control, you should use QImageReader.

suneel1310
4th March 2009, 09:07
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?

spud
4th March 2009, 15:39
Have a look at QImageIOHandler::ImageOption, in specific QImageIOHandler::ScaledSize and QImageIOHandler::supportsOption().



class MyImageHandler : public QImageIOHandler
{
...
bool supportsOption ( ImageOption option )
{
if(option==ScaledSize)
return true;
...
}
bool read ( QImage * image )
{
QSize scaledSize = option(ScaledSize).toSize();
...
}
};



QImage icon(64, 64, QImage::Format_RGB32);
QImageReader reader("XXX.abc");
reader.setScaledSize(QSize(64,64);
if (reader.read(&icon)) {
// Display icon
}

suneel1310
5th March 2009, 06:26
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?

spud
5th March 2009, 10:23
Create a QImage and then convert it.

suneel1310
5th March 2009, 10:38
But, converting from QImage to Qpixmap is expensive, interms of performance.
So, isn't there any other approach? which is good in performance.

spud
5th March 2009, 11:16
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.

suneel1310
6th March 2009, 04:41
Yes,
Thanks a lot for that info.
It really helped me.

talk2amulya
6th March 2009, 07:11
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..

spud
6th March 2009, 10:21
QPixmap contains a QImage.