关于ctmtk的显示图像

环境的准备

(1)            DCMTK开发包的官方网站是 http://www.dcmtk.org,只需要下载见图片。

(2)            cmake安装(编译)工具的官方网站是http://www.cmake.org,下载cmake2.8并安装。解压dcmtk开发包,用cmake使dcmtk开发包并生成工程文件。用cmake打开dcmtk开发包,需要说明的是几个WITH_*选项就是“DCMTK 3.5.4 - support libraries for Windows”解压出来的东西。点击两次configure之后就可以点ok生成工程文件了。

(3)            VC++编译dcmtk工程,并生成一些静态连接库。这些静态连接库和头文件是用来在VC++下开发需要使用的,将这些文件分别都复制dcmtk_libdcmtk_include中以便引用。

(4)            运行VC ,点击tools 目录的options 命令,然后在directories 环境中作以下设置:

Include files 中加入E:/dcmtk-3.5.4/dcmtk_include

Library files 中加入E:/dcmtk-3.5.4/dcmtk_lib(假设dcmtk静态连接库和头文件都放在E:/dcmtk-3.5.4中)

 

//
#include "dcmtk/dcmdata/dcdeftag.h"
#include "dcmtk/dcmdata/dcfilefo.h"
#include "dcmtk/dcmimgle/dcmimage.h"
#include "dcmtk/dcmdata/dctk.h"
#pragma comment(lib,"ofstd")
#pragma comment(lib,"dcmdata")
#pragma comment(lib,"dcmtls")
#pragma comment(lib,"dcmnet")
#pragma comment(lib,"dcmqrdb")
#pragma comment(lib,"dcmimgle")
#pragma comment(lib,"dcmimage")
#pragma comment(lib,"dcmjpeg")
#pragma comment(lib,"ijg8")
#pragma comment(lib,"ijg12")
#pragma comment(lib,"ijg16")
#pragma comment(lib,"dcmdsig")
#pragma comment(lib,"dcmsr")
#pragma comment(lib,"dcmpstat")
#pragma comment(lib,"dcmwlm")
#pragma comment(lib,"netapi32")
#pragma comment(lib,"wsock32")

//是自己添加的程序
 int i,j;
 DcmFileFormat * pDicomFile=new DcmFileFormat();//
 OFCondition Fcond=pDicomFile->loadFile("12.dcm");//打开文件,此处可以根据具体路径进行更改

 if(Fcond.good())
  pDC->TextOut(50,50,(CString )"load file success");
 else
  pDC->TextOut(50,50,(CString)"load file error");


 DcmDataset * pDataset=pDicomFile->getDataset();
 //这个pDataset里面包含了dicom文件都属性的信息,包括病人的id,姓名等以及其他,可以通过
 E_TransferSyntax xfer = pDataset->getOriginalXfer();
 const unsigned long flags = 0;
 const unsigned long fstart = 0;
 const unsigned long fcount = 0;
 DicomImage *pDiocmImage = new DicomImage((DcmObject*)pDataset, xfer, flags, fstart, fcount);

    pDiocmImage->setWindow(-600,1600);
 void * pDicomDibits;//dib设备无关位图的指针
 unsigned long iDataSize= pDiocmImage->createWindowsDIB(pDicomDibits,0,0,8,1,1);
 int wide = pDiocmImage->getWidth();
 int height = pDiocmImage->getHeight();
    //memset(pDicomDibits,100,wide*height);
 char *change;
 change=new char[wide*height];
    //change=(char*)pDicomDibits;
    memset(change,100,wide*height);
 memcpy(change,pDicomDibits,wide*height);
 

 
    //这个函数比较重要,产生dib的指针,后面的参数为表示产生第一帧的8位的dib位图。
 BITMAPINFOHEADER   BitmapInfoHeader;  
 BitmapInfoHeader.biBitCount=8;
 BitmapInfoHeader.biClrImportant=0;
 BitmapInfoHeader.biClrUsed=0;
 BitmapInfoHeader.biCompression=BI_RGB;
 BitmapInfoHeader.biPlanes=1;
 BitmapInfoHeader.biHeight= pDiocmImage->getHeight();//得到图像的高度
 BitmapInfoHeader.biWidth=  pDiocmImage->getWidth();//得到图像的宽度
 BitmapInfoHeader.biXPelsPerMeter=0;
 BitmapInfoHeader.biYPelsPerMeter=0;
 BitmapInfoHeader.biSize=sizeof(BITMAPINFOHEADER);
 BitmapInfoHeader.biSizeImage=0;

 
 RGBQUAD pColorTable[256];
 for(int i=0;i<256;i++)
 {

  pColorTable[i].rgbBlue=i;
  pColorTable[i].rgbGreen=i;
  pColorTable[i].rgbRed=i;
  pColorTable[i].rgbReserved=0;
 }
 //定义一个bmpinfo需要内存大小的内存
 char p[sizeof(BITMAPINFOHEADER)+256*4];
 memcpy(p,&BitmapInfoHeader,sizeof(BITMAPINFOHEADER));
 memcpy(p+sizeof(BITMAPINFOHEADER),pColorTable,1024);
 PBITMAPINFO BitmapInfo = (PBITMAPINFO)p;

 //颜色表
 int colorTableLng;
 colorTableLng=256;

 // 创建调色板
 HPALETTE hPalette=0,hOldPal;
 if (colorTableLng!=0)
 {
  //定义颜色表指针pColorTable,指向DIB的颜色表
  //申请缓冲区,生成LOGPALETTE结构
  LPLOGPALETTE pLogPal = (LPLOGPALETTE)new char[2*sizeof(WORD)
   +colorTableLng * sizeof(PALETTEENTRY)];
  pLogPal->palVersion = 0x300;
  pLogPal->palNumEntries =colorTableLng;
  for(int i = 0; i < colorTableLng; i++)
  {
   pLogPal->palPalEntry[i].peRed= pColorTable[i].rgbRed;
   pLogPal->palPalEntry[i].peGreen =pColorTable[i].rgbGreen;
   pLogPal->palPalEntry[i].peBlue = pColorTable[i].rgbBlue;
   pLogPal->palPalEntry[i].peFlags = 0;
  }
  //
  //创建逻辑调色板
  hPalette =::CreatePalette(pLogPal);
  // 将调色板选入系统
  hOldPal=::SelectPalette(pDC->GetSafeHdc(), hPalette, TRUE);
  //实现调色板
  pDC->RealizePalette();
  //释放缓冲区
  delete []pLogPal;
 }

 //
 //DIB显示所需要的模式
 pDC->SetStretchBltMode(COLORONCOLOR);

 //显示DIB到显示器,
 ::StretchDIBits(pDC->GetSafeHdc(), 0, 0,BitmapInfoHeader.biWidth ,BitmapInfoHeader.biHeight,
  0,0, BitmapInfoHeader.biWidth,BitmapInfoHeader.biHeight,change,BitmapInfo, DIB_RGB_COLORS, SRCCOPY);

 /

这是源程序,配置网上很多

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值