png格式图片转jpg
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)#include <vtkSmartPointer.h>
#include <vtkPNGReader.h>
#include <vtkJPEGWriter.h>
#include <vtkImageViewer2.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleImage.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>//测试文件:data/VTK-logo.png
int main(int argc, char* argv[])
{char * fileName = (char*)"D:/VTKCODE/testvtk01/1.png";//读取PNG图像vtkSmartPointer<vtkPNGReader> reader = vtkSmartPointer<vtkPNGReader>::New();reader->SetFileName(fileName);vtkSmartPointer<vtkInteractorStyleImage> style = vtkSmartPointer<vtkInteractorStyleImage>::New();//显示读取的单幅PNG图像vtkSmartPointer<vtkImageViewer2> imageViewer = vtkSmartPointer<vtkImageViewer2>::New();imageViewer->SetInputConnection(reader->GetOutputPort());vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();renderWindowInteractor->SetInteractorStyle(style);imageViewer->SetupInteractor(renderWindowInteractor);imageViewer->Render();imageViewer->GetRenderer()->ResetCamera();imageViewer->Render();imageViewer->SetSize(640, 480);imageViewer->GetRenderWindow()->SetWindowName("ReadWriteSingleImage");//保存成JPG图像vtkSmartPointer<vtkJPEGWriter> writer = vtkSmartPointer<vtkJPEGWriter>::New();writer->SetFileName("VTK-logo.jpg");writer->SetInputConnection(reader->GetOutputPort());writer->Write();renderWindowInteractor->Start();return EXIT_SUCCESS;
}
显示序列化图片:
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);#include <stdio.h>
#include <vtkSmartPointer.h>
#include <vtkStringArray.h>
#include <vtkJPEGReader.h>
#include <vtkImageViewer2.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>using namespace std;int main()
{//生成文件序列组名vtkSmartPointer <vtkStringArray> fileArray =vtkSmartPointer <vtkStringArray>::New();char fileName[128];for (int i = 1; i < 100; i++){sprintf_s(fileName, "D:/VTKCODE/testvtk01/Head/head%03d.jpg", i);string fileStr(fileName);fileArray->InsertNextValue(fileStr);}//读取JPG序列图像vtkSmartPointer <vtkJPEGReader> reader =vtkSmartPointer <vtkJPEGReader>::New();reader->SetFileNames(fileArray);//显示vtkSmartPointer<vtkImageViewer2> viewer =vtkSmartPointer<vtkImageViewer2>::New();viewer->SetInputConnection(reader->GetOutputPort());vtkSmartPointer<vtkRenderWindowInteractor> interact =vtkSmartPointer<vtkRenderWindowInteractor>::New();//默认选择第50张切片viewer->SetSlice(50);//viewer->SetSliceOrientationToXY();viewer->SetSliceOrientationToXZ();//viewer->SetSliceOrientationToYZ();viewer->SetupInteractor(interact);viewer->Render();interact->Start();return 0;
}