[vtkusers] How to read and display a JPEG image
Elvis Dowson
elvis.dowson at mac.com
Fri Oct 3 05:17:10 EDT 2008
Hi,
I'm trying to read a JPEG image and display it using
vtkActor2D, but I cant seem to get it to work. What am I missing out
here?
#include "qapplication.h"
#include <QtGui>
#include <vtkActor.h>
#include <vtkActor2D.h>
#include <vtkTextActor.h>
#include <vtkJPEGReader.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkImageMapper.h>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
#if QT_VERSION >= 0x040000
Ui::Dialog ui;
QDialog dialog;
#endif
ui.setupUi(&dialog);
dialog.setAttribute(Qt::WA_QuitOnClose);
// Qt vtk integration
vtkRenderer* ren;
ren = vtkRenderer::New();
ui.qvtkWidget->GetRenderWindow()->AddRenderer(ren);
// Declare object instance variables
vtkJPEGReader* imageReader;
vtkImageMapper* imageMapper;
vtkActor2D* mapActor;
// Initialize objects
imageReader = NULL;
imageMapper = NULL;
mapActor = NULL;
// Read 2D image file
imageReader = vtkJPEGReader::New();
imageReader->SetFileName("sample.jpg");
// Map 2D image file
imageMapper = vtkImageMapper::New();
imageMapper->SetInput(imageReader->GetOutput());
imageMapper->GetInput();
// Actor in scene
mapActor = vtkActor2D::New();
mapActor->SetMapper(imageMapper);
// Add Actor to renderer
ren->AddActor2D(mapActor);
// Reset camera
ren->ResetCamera();
// Render the scene
ren->GetRenderWindow()->Render();
// Display the dialog window
dialog.show();
return app.exec();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20081003/898aab85/attachment.htm>
More information about the vtkusers
mailing list