[vtkusers] vtkWindowToImageFilter and TvtkBorlandRenderWindow
dean.inglis at camris.ca
dean.inglis at camris.ca
Tue Apr 19 20:40:44 EDT 2005
Hi Anders,
Anders,
here is some working BCB builder 5 code you can adapt and try ...
Dean
void __fastcall TForm1::ScreenCaptureBitBtnClick(TObject *Sender)
{
SaveDlg->Options.Clear();
SaveDlg->Options << ofHideReadOnly << ofPathMustExist << ofOverwritePrompt;
SaveDlg->Filter = "Windows Bitmap files (*.bmp)|*.bmp|\
JPEG files (*.jpg;*.jpeg)|*.jpg;*.jpeg|\
Portable Network Graphics files (*.png)|*.png|\
PostScript files (*.ps)|*.ps|\
Tagged Image File Format files (*.tif;*.tiff)|*.tif;*.tiff";
SaveDlg->FilterIndex = 1;
if ( !SaveDlg->Execute() )
{
return;
}
String filename = SaveDlg->FileName;
String ext = LowerCase( ExtractFileExt( filename ) );
if ( strcmp( ext.c_str(),"" ) == 0 )
{
switch ( SaveDlg->FilterIndex )
{
case 1: ext = ".bmp"; break;
case 2: ext = ".jpg"; break;
case 3: ext = ".png"; break;
case 4: ext = ".ps"; break;
case 5: ext = ".tif"; break;
default: ext = ".png"; break;
}
filename = filename + ext;
}
vtkImageWriter* snapshotWriter = NULL;
if ( strcmp( ext.c_str(),".bmp" ) == 0 )
{
snapshotWriter = (vtkImageWriter*)vtkBMPWriter::New();
}
else if ( strcmp(ext.c_str(),".jpg") == 0 || \
strcmp(ext.c_str(),".jpeg") == 0 )
{
snapshotWriter = (vtkImageWriter*)vtkJPEGWriter::New();
}
else if ( strcmp(ext.c_str(),".png") == 0 )
{
snapshotWriter = (vtkImageWriter*)vtkPNGWriter::New();;
}
else if ( strcmp(ext.c_str(),".ps") == 0 )
{
snapshotWriter = (vtkImageWriter*)vtkPostScriptWriter::New();;
}
else if ( strcmp(ext.c_str(),".tif") == 0 || \
strcmp(ext.c_str(),".tiff") == 0 )
{
snapshotWriter = (vtkImageWriter*)vtkTIFFWriter::New();;
}
else
{
MessageDlg("Failed to write display image:\nunknown file type...",
mtError, TMsgDlgButtons() << mbOK,0);
return;
}
vtkWindowToImageFilter *windowToImage = vtkWindowToImageFilter::New();
windowToImage->SetInput( (vtkWindow*)RenderWindow1->GetRenderWindow() );
snapshotWriter->SetInput( windowToImage->GetOutput() );
snapshotWriter->SetFileName( filename.c_str() );
snapshotWriter->Write();
windowToImage->Delete();
snapshotWriter->Delete();
}
More information about the vtkusers
mailing list