[vtkusers] trouble in saving an image in VTK

Bill Lorensen bill.lorensen at gmail.com
Sun Dec 11 08:13:44 EST 2011


Chnage
pZImage->SetExtent( 0 , height , 0 , width , 0 ,0);
to
pZImage->SetExtent( 0 , height - 1, 0 , width - 1, 0 ,0);

On Thu, Dec 8, 2011 at 10:04 AM, dev <work2compilation at gmail.com> wrote:
> Hi all,
>
>
> I got the Zbuffer from the renderer Window:
>
> *float* zbuffer=renderWindow->GetZbufferData(0,0,HEIGHT-1,WIDTH-1);*
>
> And I save this zbuffer to an image (bmp), using a function:
> http://vtk.1045678.n5.nabble.com/file/n5059065/depth.jpg
> *SaveZBufferToImage( HEIGHT-1 , WIDTH-1, zbuffer1 , "zbuffer1.bmp" ); *
>
> I put the code of SaveZbufferToImage function here:
> void SaveZBufferToImage( int height , int width , float *ZBuffer , const
> char *FileImage )
> {
>         vtkImageData *pZImage = vtkImageData::New();
>
>         pZImage->SetExtent( 0 , height , 0 , width , 0 ,0);
>         pZImage->SetOrigin( 0.0 , 0.0 , 0.0 );
>         pZImage->SetSpacing(1.0,1.0,1.0);
>         pZImage->SetScalarTypeToUnsignedChar();
>         pZImage->SetNumberOfScalarComponents( 1 );
>         pZImage->AllocateScalars();
>
>                 unsigned char *zPtr= static_cast<unsigned char *>
> (pZImage->GetScalarPointer(0.0,0.0,0.0));
>
>        for( int i = 0 ; i < height * width ; i++ )
>        {
>                 zPtr[i] = 255-ZBuffer[i]*255;
>        }
>
>         vtkBMPWriter *pDepthImageWriter = vtkBMPWriter::New();
>         pDepthImageWriter->SetInput( pZImage );
>         pDepthImageWriter->SetFileName( FileImage );
>         pDepthImageWriter->Write();
> }
>
> And I get an image with a *white band above as you can see in the image that
> I attached*. Perhaps I have a problem of dimensions, but I didn't find
> anything.
>
> Please help
>
> Thank you
>
> --
> View this message in context: http://vtk.1045678.n5.nabble.com/trouble-in-saving-an-image-in-VTK-tp5059065p5059065.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers



-- 
Unpaid intern in BillsBasement at noware dot com



More information about the vtkusers mailing list