[vtkusers] writing images from window to file in vtk4

Chiang, Wen-Hsing wchiang at sspa.com
Sun Jan 20 02:26:47 EST 2002


Mike,

Instead of rendering the image to a window, I render it to the memory
and then retrive it as usual. It is often better to render to the
memory, because the "screen" may contain unclosed dialog boxes and other
message boxes. 

Here is the code segment that I used in my vc++ code, hope it helps:

  //m_RenderWindow is an instance of vtkWin32OpenGLRenderWindow,
  //it displays the image on screen, if the image is rendered to the
screnn
  int*   size   = m_RenderWindow->GetSize();
 
  //Setup memory rendering
  m_RenderWindow->SetupMemoryRendering( size[0],
size[1],GetDC()->m_hAttribDC);
  m_RenderWindow->Render();
 
  //Construct Writer and ImageFilter
  vtkBMPWriter*    BitmapWriter = vtkBMPWriter::New();
  vtkWindowToImageFilter * ImageFilter  = vtkWindowToImageFilter::New();
//Put the vtkWindow::m_RenderWindow to vtkWindowToImageFilter 
  ImageFilter->SetInput(m_RenderWindow);
 
  //Write the image
  BitmapWriter->SetInput(ImageFilter->GetOutput());
  BitmapWriter->SetFileName(LPTSTR(LPCTSTR(fileDlg.GetPathName())));
  BitmapWriter->Write();
 
  //Delete Writer and ImageFilter
  BitmapWriter->Delete();
  ImageFilter->Delete();
 
  //Resume screen rendering
  m_RenderWindow->ResumeScreenRendering();
  
 
Wen-Hsing Chiang
 
>From: Michael Halle <halazar at media.mit.edu>
>To: vtkusers at public.kitware.com
>Subject: [vtkusers] writing images from window to file in vtk4
>Date: Fri, 18 Jan 2002 16:16:47 +0000
>
>I feel this must be an embarrassingly simple question, but...
>
>I'm using vtk4, and I want to write an image out to a file.  That means
>using
>vtkWindowToImageFilter and connecting it to an ImageWriter (the PNG
one,
>for
>instance).
>
>I write out the file once, fine.  I change the scene, write the file
again,
>I get the same image.  The file is getting written, just with the old
>image.
>
>I've played with adding various calls to "Update","UpdateInformation",
and
>"ReleaseDataFlagOn/Off", (heck, even "Render"), and I have been unable
to
>get
>the image to change after the first render.
>
>Am I missing something obvious here?  I can post code if it's
>non-trivial....
>
>Thanks.
>
>        --Mike
>
>_______________________________________________

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 6490 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20020120/7cd43665/attachment.bin>


More information about the vtkusers mailing list