[vtkusers] how to _ color_ write on a vtkImageCanvasSource2D ?

Sebastien_MARAUX maraux at ondim.fr
Wed Jun 5 15:25:52 EDT 2002


Answer : 

I Just did not know that it was needed to set 

vtkImageData::SetNumberOfScalarComponents(3);

in addition to 
vtkImageData::SetScalarTypeToUnsignedChar();
to be able to set rgb values (0-255 range)

Does 4 components allow transparency when exported as PNG ?
  ----- Original Message ----- 
  From: Sebastien_MARAUX 
  To: vtk mailing list 
  Sent: Wednesday, June 05, 2002 1:49 PM
  Subject: [vtkusers] how to _ color_ write on a vtkImageCanvasSource2D ?


  I would like to draw lines, etc. on a (jpeg read) image data.
  I use a vtkimageCanvasSource2D to gain access to the 
  image data , but when I read the re exported image as a 
  jpeg file, I can only see white drawings.

  What do I do wrong ?

  snippet : 
  /*==============================================*/

   vtkImageData *fond = vtkImageData::New();
   fond->SetDimensions(2048,2048,1);
   fond->SetImageData(jpgReader->GetOutput());
   fond->SetScalarTypeToUnsignedChar();
   fond->SetNumberOfScalarComponents(3);
   fond->SetExtent(jpgReader->GetOutput()->GetExtent());

   vtkImageCanvasSource2D *vicsSIG = vtkImageCanvasSource2D::New();
   vicsSIG->SetScalarTypeToUnsignedChar();
   vicsSIG->SetNumberOfScalarComponents(3);
   vicsSIG->SetExtent(fond->GetExtent());
   vicsSIG->SetDrawColor(0.0,0.0,0.0);
   vicsSIG->FillBox(0,texSize[0],0,texSize[1]);
   vicsSIG->SetDrawColor(255.0,0.0,0.0);
   vicsSIG->FillBox(100,500,100,500);
   
   vicsSIG->SetDrawColor(255.0,255.0,0,0);
   vicsSIG->DrawSegment(0,0,1024,1024);
   vicsSIG->Update();

   vtkJPEGWriter *jpgWriter2=vtkJPEGWriter::New();
   jpgWriter2->SetInput(vicsSIG->GetOutput());
   jpgWriter2->SetFileName("sortie2048.jpg");
   jpgWriter2->SetQuality(95);
   jpgWriter2->ProgressiveOn();
   tPrint("\toutputing texture : sorti2048.jpg\n");

  /*==============================================*/

  Sebastien MARAUX
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20020605/afe6a38b/attachment.htm>


More information about the vtkusers mailing list