您的位置:首页 > 其它

vtk实战(四十四)——写入jpg格式

2016-04-30 13:43 561 查看
#include <vtkSmartPointer.h>
#include <vtkImageCanvasSource2D.h>
#include <vtkJPEGWriter.h>

int main(int vtkNotUsed(argc), char* vtkNotUsed(argv)[])
{
std::string outputFilename = "output.jpg";

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(0, 127, 255);
imageSource->FillBox(extent[0], extent[1], extent[2], extent[3]);

imageSource->SetDrawColor(255, 255, 255);
imageSource->FillBox(40, 70, 20, 50);

vtkSmartPointer<vtkJPEGWriter> writer =
vtkSmartPointer<vtkJPEGWriter>::New();
writer->SetFileName(outputFilename.c_str());
writer->SetInputConnection(imageSource->GetOutputPort());
writer->Write();
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: