您可以利用 AForge .NET Framework,它是用于图像处理的出色 .NET 库。内置的 .NET Picturebox 无法使用 System.Drawing.Imaging.PixelFormat.Format16bppGrayScale 显示图像,但 AForge 库有自己的Picturebox控件,检查一下。它需要一个 .NET 映像。
您可以使用 NuGet 轻松地将 AForge 包含到您的项目中:
Install-Package AForge.Controls
Install-Package AForge.Imaging
要不就
Install-Package AForge
下面的示例代码:
//SOME BYTES
//Load here the DICOM image
int width=640, height=480;
int numberOfPixels = width*height;
byte[] source = new byte[2*numberOfPixels];
//With AFORGE
var image = AForge.Imaging.UnmanagedImage.Create(width, height, System.Drawing.Imaging.PixelFormat.Format16bppGrayScale);
IntPtr ptrToImage = image.ImageData;
//Copies the bytes from source to the image
//System.Runtime.InteropServices
Marshal.Copy(source, 0, ptrToImage,numberOfPixels);
//WITH .NET
System.Drawing.Bitmap bitmapImage = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format16bppGrayScale);
var imageData = bitmapImage.LockBits(new System.Drawing.Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format16bppGrayScale);
Marshal.Copy(source, 0, imageData.Scan0, numberOfPixels);
bitmapImage.UnlockBits(imageData);