c# dcm格式转换为jpg
时间: 2023-12-05 22:40:00 浏览: 54
以下是使用C#将DCM格式转换为JPG格式的示例代码:
```csharp
using System.Drawing;
using Dicom;
using System.IO;
namespace DcmToJpg
{
class Program
{
static void Main(string[] args)
{
// 读取DCM文件
DicomFile dicomFile = DicomFile.Open("test.dcm");
// 获取像素数据
DicomPixelData pixelData = DicomPixelData.Create(dicomFile.Dataset);
// 将像素数据转换为位图
Bitmap bitmap = new Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, bitmap.PixelFormat);
pixelData.CopyTo(bitmapData.Scan0, (uint)(bitmapData.Stride * bitmapData.Height), 0);
bitmap.UnlockBits(bitmapData);
// 保存为JPG文件
bitmap.Save("test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
}
```
需要注意的是,上述代码需要使用Dicom库,可以通过NuGet安装。同时,需要将DCM文件放在程序运行的目录下。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)