I want to enlarge a image (*.dcm file). when i Use createScaledImage function, it show a messagebox to tell me hint of memory. The following is my code:
PS:sorry,my english 's poor. my email 's luyuxibaby@163.com
Code: Select all
DcmFileFormat * pDicomFile=new DcmFileFormat();
OFCondition Fcond=pDicomFile->loadFile("txt.DCM"); CDC *pDC = GetDC();
if(Fcond.good())
pDC->TextOut(50,50,(CString )"load file success");
else
pDC->TextOut(50,50,(CString)"load file error");
DcmDataset * pDataset=pDicomFile->getDataset();
E_TransferSyntax xfer=pDataset->getOriginalXfer();
DicomImage *pDicomImg = new DicomImage((DcmObject * )pDataset, xfer);
pDicomImg=new DicomImage("TXT.DCM",0,0,0);
unsigned long imagewidth;
unsigned long imagehight;
DicomImage *im=pDicomImg->createScaledImage(imagewidth,imagehight,0,0);
void * pDicomDibits;
unsigned long iDataSize= pDicomImg->createWindowsDIB(pDicomDibits,0,0,8,1,1);
BITMAPINFOHEADER BitmapInfoHeader;
BitmapInfoHeader.biBitCount=8;
BitmapInfoHeader.biClrImportant=0;
BitmapInfoHeader.biClrUsed=0;
BitmapInfoHeader.biCompression=BI_RGB;
BitmapInfoHeader.biPlanes=1;
BitmapInfoHeader.biHeight=pDicomImg->getHeight();
BitmapInfoHeader.biWidth=pDicomImg->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;
}
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)
{
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;
}
pDC->SetStretchBltMode(COLORONCOLOR);
::StretchDIBits(pDC->GetSafeHdc(), 0, 0,BitmapInfoHeader.biWidth ,BitmapInfoHeader.biHeight,
0,0, BitmapInfoHeader.biWidth,BitmapInfoHeader.biHeight,pDicomDibits,BitmapInfo, DIB_RGB_COLORS, SRCCOPY);
}