我已经将C#位图转换为无符号char数组,并能够使用以下代码显示图像:
void VTKCaller::Render2DImage(unsigned char * iImageBytes, int iWidth, int iHeight, int iBytesPerPixel, int iStrideSize)
{
vtkSmartPointer<vtkImageData> imageData = vtkSmartPointer<vtkImageData>::New();
imageData->SetDimensions(iWidth, iHeight, 1);
imageData->SetOrigin(0.0, 0.0, 0.0);
imageData->SetSpacing(1.0, 1.0, 1.0);
imageData->AllocateScalars(VTK_UNSIGNED_CHAR, iBytesPerPixel);
// Some loops here ...
imageData->SetScalarComponentFromFloat(...);
vtkSmartPointer<vtkImageMapper> imageMapper = vtkSmartPointer<vtkImageMapper>::New();
imageMapper->SetInputData(imageData);
imageMapper->SetColorWindow(255); // width of the color range to map to
imageMapper->SetColorLevel(127.5); // center of the color range to map to
vtkSmartPointer<vtkActor2D> actor = vtkSmartPointer<vtkActor2D>::New();
actor->SetMapper(imageMapper);
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renWin);
renWin->Render();
renderWindowInteractor->Start();
}
但是图像不会调整大小。我试图actor-> SetWidth或SetHeight,它不起作用。请指教。非常感谢。
答案 0 :(得分:0)
这是如何调整图像大小的方法(来自VTK示例):
vtkSmartPointer<vtkImageResize> resize =
vtkSmartPointer<vtkImageResize>::New();
resize->SetInputData(imageData);
resize->SetOutputDimensions(newSizeX, newSizeY, 1);
resize->Update();
而且,我不确定,是否仍然需要将actor标记为已修改,以便刷新输出:
actor->Modified();