PDA

View Full Version : Reading an image with extension *.tif



vermarajeev
24th March 2007, 05:15
Hi guys,
I'm working on zooming options and want to read an image with tif extension. When I use an image with extension jpeg it works fine. But the image is not displayed when I use a file with extension tif.

Here is the sample code of constructor

myWidget::myWidget( const char* imageFileName, QWidget *parent )
: QWidget( parent )
{
m_pm = new QPixmap( imageFileName );
factorZoom = 0.30001;
setMinimumSize( m_pm->width()*factorZoom, m_pm->height(), factorZoom );
}
When imageFileName is "test.jpeg" program works fine and the image is viewed and zoomed.
When imageFileName is "test.tif", nothing is displayed.


When I double clik on "tif" image from outside. It says "Drawing failed" in "Windows Picture and Fax Viewer on windows Xp".

I can view the image using Irfan view. The properties of the image are as follows

Dimensions: 1110 x 1118
Type: TIF image
Size: 2.39 MB

How to display a "tif" image on a widget????

Thanks

Kumosan
24th March 2007, 06:52
How to display a "tif" image on a widget????


If you check out the supported image formats in the Qt docs, you won't find tif. If it is not supported, you are on your own.

vermarajeev
24th March 2007, 07:19
If you check out the supported image formats in the Qt docs, you won't find tif. If it is not supported, you are on your own.

I know Qt doesnt support tif format but there has to be some workaround. I want to know how that is possible???

And by the way what do you mean by "If it is not supported, you are on your own"

Kumosan
24th March 2007, 07:42
And by the way what do you mean by "If it is not supported, you are on your own"

You have to find your own solution.
Use the qt 4.3 beta.
Write your own tif plugin
Use a third party lib, e.g. with imagemagick.

wysota
24th March 2007, 09:25
There is a TIFF plugin available - http://artis.imag.fr/Software/TiffIO/

vermarajeev
26th March 2007, 04:47
There is a TIFF plugin available - http://artis.imag.fr/Software/TiffIO/

If wysota,
I tried running the code provided, using the link. First I ran demo.pro to see how tiff images can be loaded. There was no tif option available. Then I ran test.pro as said in the document. I get this messages


D:\TiffIo-1.30e\TiffIO-130e>test-debug.exe
*** NO JPEG SUPPORT ***
zip compression support
lzw compression support
packbits (aka rle) supported
pixarlog supported
Using temp dir = C:\DOCUME~1\rajeevv\LOCALS~1\Temp
All images checked ok (50 reads, 95 write/rereads, 9 unsupported)

Why m I not getting tif after i run demo.pro.... How can I solve the above problem????

Thanks

wysota
26th March 2007, 08:09
Do you have libtiff? Did you install the plugin in the proper place?

BTW. I saw that Qt (at least the 4.3 beta version) can build its own TIFF plugin, so you might try recompiling Qt as well. Remember that you need libtiff and its development files to compile the plugin.

vermarajeev
26th March 2007, 08:26
Do you have libtiff? Did you install the plugin in the proper place?

BTW. I saw that Qt (at least the 4.3 beta version) can build its own TIFF plugin, so you might try recompiling Qt as well. Remember that you need libtiff and its development files to compile the plugin.

To solve the above problem I first tried to create my own plugin and see how it works.
I just tried out something like this

//plugin.h
#include <qwidgetplugin.h>

class CustomWidgetPlugin : public QWidgetPlugin
{
public:
CustomWidgetPlugin();

QStringList keys() const;
QWidget* create( const QString &classname, QWidget* parent = 0, const char* name = 0 );
QString group( const QString& ) const;
QIconSet iconSet( const QString& ) const;
QString includeFile( const QString& ) const;
QString toolTip( const QString& ) const;
QString whatsThis( const QString& ) const;
bool isContainer( const QString& ) const;
};

//plugin.cpp

#include "plugin.h"
#include "../fileChooser/filechooser.h"

static const char *filechooser_pixmap[] = {
"22 22 8 1",
" c Gray100",
". c Gray97",
"X c #4f504f",
"o c #00007f",
"O c Gray0",
"+ c none",
"@ c Gray0",
"# c Gray0",
"++++++++++++++++++++++",
"++++++++++++++++++++++",
"++++++++++++++++++++++",
"++++++++++++++++++++++",
"+OOOOOOOOOOOOOOOOOOOO+",
"OOXXXXXXXXXXXXXXXXXXOO",
"OXX. OO OO O",
"OX. oo O O",
"OX. oo O .O",
"OX ooo oooo O O",
"OX oo oo oo O O",
"OX oooo oo oo O O",
"OX oo oo oo oo O O",
"OX oo oo oo oo O O",
"OX oooo oooo O O",
"OX OO OO O",
"OO..................OO",
"+OOOOOOOOOOOOOOOOOOOO+",
"++++++++++++++++++++++",
"++++++++++++++++++++++",
"++++++++++++++++++++++",
"++++++++++++++++++++++"
};

CustomWidgetPlugin::CustomWidgetPlugin()
{
}

QStringList CustomWidgetPlugin::keys() const
{
QStringList list;
list << "FileChooser";
return list;
}

QWidget* CustomWidgetPlugin::create( const QString &key, QWidget* parent, const char* name )
{
if ( key == "FileChooser" )
return new FileChooser( parent, name );
return 0;
}

QString CustomWidgetPlugin::group( const QString& feature ) const
{
if ( feature == "FileChooser" )
return "Input";
return QString::null;
}

QIconSet CustomWidgetPlugin::iconSet( const QString& ) const
{
return QIconSet( QPixmap( filechooser_pixmap ) );
}

QString CustomWidgetPlugin::includeFile( const QString& feature ) const
{
if ( feature == "FileChooser" )
return "filechooser.h";
return QString::null;
}

QString CustomWidgetPlugin::toolTip( const QString& feature ) const
{
if ( feature == "FileChooser" )
return "File Chooser Widget";
return QString::null;
}

QString CustomWidgetPlugin::whatsThis( const QString& feature ) const
{
if ( feature == "FileChooser" )
return "A widget to choose a file or directory";
return QString::null;
}

bool CustomWidgetPlugin::isContainer( const QString& ) const
{
return FALSE;
}


Q_EXPORT_PLUGIN( CustomWidgetPlugin )
This is an example from Qt docs.
Here is a sample program I have used

//test.h
#ifndef TEST_H
#define TEST_H

#include <qwidget.h>

class testPlugin : public QWidget
{
public:
testPlugin(QWidget* parent = 0, const char* name = 0);
~testPlugin(){}
private:
};
#endif


//TEST.CPP
#include "test.h"


testPlugin::testPlugin(QWidget* parent, const char* name)
:QWidget(parent, name)
{
//what code to write to test the plugin.
}

Now how do I make use of plugin defined above. I read "Creating Custom Widgets" provided by QtAssistance in qt3.3.5. Here is the link http://doc.trolltech.com/3.3/designer-manual-7.html
I too searched qtcenter search but the answers are all related to qt4.

Also how to install the plugin?

Thanks

wysota
26th March 2007, 08:33
But what does a widget plugin has to do with an imageformat plugin (apart from the "plugin" in the name)?

The imageformat plugin has to be placed in $QTDIR/plugins/imageformats.

vermarajeev
26th March 2007, 09:40
But what does a widget plugin has to do with an imageformat plugin (apart from the "plugin" in the name)?

The imageformat plugin has to be placed in $QTDIR/plugins/imageformats.

Hi wysota,
Thanks for you reply.

Before using plugin I should know how I can use it. So I have a sample program to see how plugin works.

This path $QTDIR/plugins/imageformats helped to fix my first problem. Thanks once more.

wysota
26th March 2007, 10:26
Please don't mix two completely different problems in the same forum thread.

vermarajeev
26th March 2007, 10:35
Please don't mix two completely different problems in the same forum thread.

Sorry, I have edited and made the corrections. :rolleyes: