[vtkusers] How to read and display a JPEG image
Elvis Dowson
elvis.dowson at mac.com
Fri Oct 3 06:04:11 EDT 2008
Sorry,
I made it work using vtkImageActor but it doesn't work
with vtkActor2D.
Here is the code that works using vtkImageActor (This displays the
image in 3D, but I want to use vtkActor2D but that doesnt seem to work)
Working code
// Declare object instance variables
vtkJPEGReader* imageReader;
vtkImageMapper* imageMapper;
vtkImageActor* mapActor;
// Initialize objects
imageReader = NULL;
imageMapper = NULL;
mapActor = NULL;
// Read 2D image file
imageReader = vtkJPEGReader::New();
imageReader->SetFileName("/Users/elvis/Image/sample.jpg");
imageReader->Update();
// Map 2D image file
imageMapper = vtkImageMapper::New();
imageMapper->SetInput(imageReader->GetOutput());
// Actor in scene
mapActor = vtkImageActor::New();
mapActor->SetInput(imageMapper->GetInput());
// Add Actor to renderer
ren->AddActor(mapActor);
Code that doesn't display the image
Here is the attempt at using vtkActor2D but it doesnt work. Could some
one please tell me how I can get this to work?
// 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("/Users/elvis/Image/sample.jpg");
imageReader->Update();
// Map 2D image file
imageMapper = vtkImageMapper::New();
imageMapper->SetInput(imageReader->GetOutput());
// Actor in scene
mapActor = vtkActor2D::New();
mapActor->SetMapper(imageMapper);
// Add Actor to renderer
ren->AddActor(mapActor);
Best regards,
Elvis Dowson
On Oct 3, 2008, at 1:43 PM, Elvis Dowson wrote:
> Hi,
> I found out the reason why, I had to explicitly specify the
> full path to the image file name and it worked.
>
> imageReader->SetFileName("/Users/elvis/Image/sample.jpg");
> imageReader->Update();
>
> Best regards,
>
> Elvis Dowson
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20081003/01067013/attachment.htm>
More information about the vtkusers
mailing list