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.
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".
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.
Re: QImageIOPlugin, support for new image format.
Well you could always use
If you want more control, you should use QImageReader.
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?
Re: QImageIOPlugin, support for new image format.
Have a look at QImageIOHandler::ImageOption, in specific QImageIOHandler::ScaledSize and QImageIOHandler::supportsOption().
Code:
{
...
bool supportsOption ( ImageOption option )
{
if(option==ScaledSize)
return true;
...
}
{
QSize scaledSize
= option
(ScaledSize
).
toSize();
...
}
};
Code:
reader.
setScaledSize(QSize(64,
64);
if (reader.read(&icon)) {
// Display icon
}
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?
Re: QImageIOPlugin, support for new image format.
Create a QImage and then convert it.
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.
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.
Re: QImageIOPlugin, support for new image format.
Yes,
Thanks a lot for that info.
It really helped me.
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..
Re: QImageIOPlugin, support for new image format.
QPixmap contains a QImage.