#include <vtkImageData.h>
#include <vtkPNGWriter.h>
#include <vtkSmartPointer.h>
#include <vtkImageCanvasSource2D.h>
#include <vtkImageCast.h>
int main()
{
std::string outputFilename;
outputFilename = "output.png";
int extent[6] = { 0, 99, 0, 99, 0, 0 };
vtkSmartPointer<vtkImageCanvasSource2D> imageSource =
vtkSmartPointer<vtkImageCanvasSource2D>::New();
imageSource->SetExtent(extent);
imageSource->SetScalarTypeToUnsignedChar();
imageSource->SetNumberOfScalarComponents(3);
imageSource->SetDrawColor(127, 45, 255);
imageSource->FillBox(0, 99, 0, 99);
imageSource->SetDrawColor(255, 255, 255);
imageSource->FillBox(40, 70, 20, 50);
imageSource->Update();
vtkSmartPointer<vtkImageCast> castFilter =
vtkSmartPointer<vtkImageCast>::New();
castFilter->SetOutputScalarTypeToUnsignedChar();
castFilter->SetInputConnection(imageSource->GetOutputPort());
castFilter->Update();
vtkSmartPointer<vtkPNGWriter> writer =
vtkSmartPointer<vtkPNGWriter>::New();
writer->SetFileName(outputFilename.c_str());
writer->SetInputConnection(castFilter->GetOutputPort());
writer->Write();
return 0;
}
vtk實戰(四十五)——寫入png格式
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.