private void Window_Activated(object sender, EventArgs e) { // 一定要先 vtkformhost.Child = vtkControl;下面三条顺序不能乱 否则报错 切记! vtkformhost.Child = vtkControl; vtkRenderWindow renWin = vtkControl.RenderWindow; vtkRenderer aRenderer = renWin.GetRenderers().GetFirstRenderer(); renWin.AddRenderer(aRenderer); Marshal.Copy(ys1, 0, temp128, imgLine * imgPixel * imgNum); temp.SetArray(temp128, imgLine * imgPixel * imgNum, 1); testimgdata.SetDimensions(imgLine, imgPixel, imgNum); testimgdata.SetSpacing(1, 1, 4); testimgdata.SetScalarTypeToUnsignedChar(); testimgdata.SetNumberOfScalarComponents(1); testimgdata.AllocateScalars(); testimgdata.GetPointData().SetScalars(temp); testimgdata.Modified(); VtkSetColor(); VtkSetOpacity(); volumeProperty.SetColor(colorTransferFunction); volumeProperty.SetScalarOpacity(opacityTransferFunction); volumeProperty.ShadeOn(); volumeProperty.SetInterpolationTypeToLinear(); volumeMapper.SetVolumeRayCastFunction(compositeFunction); volumeMapper.SetInput(testimgdata); volume.SetMapper(volumeMapper); volume.SetProperty(volumeProperty); aCamera.SetViewUp(0, -1, 0); aCamera.SetPosition(-1, 0, 1); aCamera.ComputeViewPlaneNormal(); aRenderer.AddVolume(volume); aRenderer.SetBackground(0, 0, 0.6); aRenderer.SetActiveCamera(aCamera); aRenderer.ResetCamera(); renWin.SetSize(800, 800); renWin.Render(); }