SOS:about createScaledImage function

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
luyuxibaby
Posts: 6
Joined: Mon, 2011-04-18, 04:27

SOS:about createScaledImage function

#1 Post by luyuxibaby »

hello everybody

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);
	
}

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#2 Post by Jörg Riesmeier »

What exactly is your question?

Looking at you code, there seem to be a couple of minor and major issues, e.g.:
  • You are loading the same file twice (filename "txt.DCM" vs. "TXT.DCM").
  • You are using the same pointer for different DicomImage objects without deleting the previous instance.
  • You are calling createScaledImage() with undefined values for the integer variables for width and height.
  • ... and so on ...

luyuxibaby
Posts: 6
Joined: Mon, 2011-04-18, 04:27

#3 Post by luyuxibaby »

Jörg Riesmeier wrote:What exactly is your question?

Looking at you code, there seem to be a couple of minor and major issues, e.g.:
  • You are loading the same file twice (filename "txt.DCM" vs. "TXT.DCM").
  • You are using the same pointer for different DicomImage objects without deleting the previous instance.
  • You are calling createScaledImage() with undefined values for the integer variables for width and height.
  • ... and so on ...
Thank you very much, you gave me a lot of help. Best wishes for you

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest