[vtkusers] How to create an image from scratch in memory in VTK

Deepak Roy cdeepakroy at yahoo.com
Fri Dec 9 13:26:46 EST 2005


hello,
  Does anyone know how to create an image from scratch in memory in VTK.
  I tried this and many other things but it doesnt work.....
   
  **************************************************************************************************
  vtkImageData *pZImage = vtkImageData::New();
  pZImage->SetDimensions( wx , wy , 1 );
  pZImage->SetOrigin( 0 , 0 , 0 );
  pZImage->SetSpacing( 1 , 1 , 1 );
  pZImage->SetScalarTypeToUnsignedChar();
  pZImage->SetNumberOfScalarComponents( 1 );
  pZImage->AllocateScalars();
   
  vtkUnsignedCharArray *pScalars = (vtkUnsignedCharArray *) pZImage->GetPointData()->GetScalars();
   
  
for( int i = 0 ; i < wx ; i++ )
  {
    for( int j = 0 ; j < wy ; j++ )
  {
    int index = i * j;
   
  pScalars->SetValue( index , 0 ); 
  } 
  }
   
  pZImage->GetPointData()->SetScalars( pScalars );
   
  vtkJPEGWriter *pImageWriter = vtkJPEGWriter::New();
  pImageWriter ->SetInput( pZImage );
  pImageWriter ->SetQuality( 100.0 );
  pImageWriter ->SetFileName( strImageFile );
  pImageWriter ->ProgressiveOff();
  pImageWriter ->Write();
   
  *************************************************************************************************
   
  I am sure there should be many ways.......
   
  Thanks in advance
   
  Regards,
   
  Deepak Roy


			
---------------------------------
Yahoo! Shopping
 Find Great Deals on Holiday Gifts at Yahoo! Shopping 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20051209/b1e00e2c/attachment.htm>


More information about the vtkusers mailing list