对于图形的输入最重要的是,要了解要输出的图形的格式,而基础的方法是一样的,
在本博客的vc++分类里面已经有了位图的输出方式,本文再提供一个用vtk输入jpg图片的c++类
#include "vtkRenderWindow.h"
#include "vtkWindowToImageFilter.h"
#include "vtkBMPWriter.h"
class CPutOutImage
{
public:
CPutOutImage();
virtual ~CPutOutImage();
public:
void SetFile(CString str);
void PutOutImage(vtkRenderWindow* pRenderWindow);
public:
CString m_str;
//vtkRenderWindow* pRenderWindow;//输入
vtkWindowToImageFilter* pWindowToImageFilter;
vtkBMPWriter* pBMPWriter;
};
CPutOutImage::CPutOutImage()
{
pWindowToImageFilter = vtkWindowToImageFilter::New();
pBMPWriter = vtkBMPWriter::New();
}
CPutOutImage::~CPutOutImage()
{
pWindowToImageFilter->Delete();
pBMPWriter->Delete();
}
void CPutOutImage::SetFile(CString str)
{
m_str = str;
}
void CPutOutImage::PutOutImage(vtkRenderWindow* pRenderWindow)
{
pWindowToImageFilter->SetInput(pRenderWindow);
pWindowToImageFilter->Update();
pBMPWriter->SetInputConnection(pWindowToImageFilter->GetOutputPort());
pBMPWriter->SetFileName(m_str);
pRenderWindow->Render();
pWindowToImageFilter->Modified();
pBMPWriter->Write();
}
使用方法,响应按钮消息,输入render及打印图片的输入路径即可
if (!m_ImagePath)
{
AfxMessageBox("请输入路径");
}
m_GetPath.GetWindowText(m_ImagePath);
m_mange.PutoutImage(m_ImagePath);