Click here to Skip to main content
15,890,438 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to calculate the Bandwidth of our computer Pin
Anshul Mehra2-Nov-04 3:20
professionalAnshul Mehra2-Nov-04 3:20 
GeneralRe: How to calculate the Bandwidth of our computer Pin
Antony M Kancidrowski2-Nov-04 4:04
Antony M Kancidrowski2-Nov-04 4:04 
AnswerRe: How to calculate the Bandwidth of our computer Pin
Selvam R2-Nov-04 2:56
professionalSelvam R2-Nov-04 2:56 
AnswerRe: How to calculate the Bandwidth of our computer Pin
ThatsAlok3-Nov-04 17:57
ThatsAlok3-Nov-04 17:57 
QuestionWhat is the defference about _T("abc") and "abc"? Pin
freehawk1-Nov-04 23:41
freehawk1-Nov-04 23:41 
AnswerRe: What is the defference about _T("abc") and "abc"? Pin
Pharago1-Nov-04 23:57
Pharago1-Nov-04 23:57 
AnswerRe: What is the defference about _T("abc") and "abc"? Pin
RChin2-Nov-04 0:13
RChin2-Nov-04 0:13 
GeneralCreating 16 color bitmap from DC Pin
Vinaya1-Nov-04 23:03
Vinaya1-Nov-04 23:03 
Hi,

I need to modify a 16 color bmp and then save it as a seperate file. I loaded a 16 color 48x48 bmp file on DC using the LoadImage() and BitBlt() API. Using GDI functions, I change the display on the DC, say draw a line on the DC, on top of the image displayed. Now I need to capture the current DC ( bmp image + the changes,i.e., the line) and create a new BMP file.

For 256 color and 16 color BMP file, the new BMP created is a plain white imgage, if I load the image with 'LR_CREATEDIBSECTION' flag in LoadImage API. else I get am able to create the file, but the image size is different. For the 24 bpp the application is working fine. Where am i doing wrong. I am using the 'CreateCompatibleBitmap()' to create the bitmap from DC. Is there any other way?.

<br />
	HBITMAP hBMP;<br />
	RECT r;<br />
	GetClientRect(GetDlgItem(hWnd,IDC_STATIC_1),&r);<br />
	HDC memDC = CreateCompatibleDC ( pDC );<br />
	hBMP = (HBITMAP)LoadImage(hResDll ,filename,IMAGE_BITMAP,  0, 0, LR_LOADFROMFILE);<br />
	SelectObject ( memDC, hBMP );<br />
	BitBlt(pDC,r.left ,r.top ,imgWidth,imgHeight ,memDC,0,0,SRCCOPY);<br />
	DeleteObject(hBMP);

..............................
To capture the modified BMP from DC
.............................
  <br />
        RECT rc;<br />
	GetClientRect(GetDlgItem(hWndDlg,IDC_STATIC_1),&rc);<br />
	HDC hScreenDC = GetWindowDC(GetDlgItem(hWndDlg,IDC_STATIC_1)); <br />
	HDC hmemDC = CreateCompatibleDC(hScreenDC);   <br />
	int ScreenWidth = rc.right;<br />
	int ScreenHeight = rc.bottom;<br />
	HBITMAP hmemBM = CreateCompatibleBitmap(hScreenDC, ScreenWidth ,ScreenHeight );<br />
	SelectObject(hmemDC, hmemBM);<br />
	bufLen= filesize;<br />
	HGLOBAL hpxldata = GlobalAlloc(GMEM_FIXED ,imgWidth * imgHeight * 3 ); <br />
	void * lpvpxldata = GlobalLock(hpxldata);<br />
<br />
	// fill .bmp - structures<br />
	BITMAPINFO bmInfo;<br />
	bmInfo.bmiHeader.biSize = 40;<br />
	bmInfo.bmiHeader.biWidth = imgWidth;<br />
	bmInfo.bmiHeader.biHeight = imgHeight;<br />
	bmInfo.bmiHeader.biPlanes = 1;<br />
	bmInfo.bmiHeader.biBitCount = 24;<br />
	bmInfo.bmiHeader.biCompression = 0;<br />
	bmInfo.bmiHeader.biSizeImage = 0;<br />
	bmInfo.bmiHeader.biXPelsPerMeter = 0;<br />
	bmInfo.bmiHeader.biYPelsPerMeter = 0;<br />
	bmInfo.bmiHeader.biClrUsed = 0;<br />
	bmInfo.bmiHeader.biClrImportant = 0;<br />
	BITMAPFILEHEADER bmFileHeader;<br />
	bmFileHeader.bfType = 19778;<br />
	bmFileHeader.bfSize = filesize; <br />
	bmFileHeader.bfReserved1 = 0;<br />
	bmFileHeader.bfReserved2 = 0;<br />
	bmFileHeader.bfOffBits = 54;<br />
	// copy bitmap data into global memory<br />
	StretchBlt(hmemDC,0 ,0 ,imgWidth ,imgHeight,hScreenDC,0,0,ScreenWidth,ScreenHeight ,SRCCOPY);<br />
	int nret = GetDIBits(hmemDC, hmemBM, 0, imgHeight, lpvpxldata, &bmInfo, DIB_RGB_COLORS);<br />
	<br />
	<br />
	ImgBuffer = (void*)malloc(bufLen); <br />
	memset(ImgBuffer, 0, bufLen); <br />
	memcpy((char*)ImgBuffer, (char*)&bmFileHeader,14);<br />
	memcpy((char*)ImgBuffer + 14, (char*)&bmInfo, 40);<br />
	memcpy((char*)ImgBuffer+54, (char*)lpvpxldata,bufLen - 54); <br />
	FILE *fn = fopen("e:\\vinaya\\testimg.bmp","w");	<br />
	fn = fopen("e:\\NewImg.bmp","w");<br />
	fwrite((char*) ImgBuffer ,sizeof(char), filesize, fn);<br />
	fclose(fn);<br />
	fn = NULL;<br />
	<br />
	// clean up<br />
	int i = GlobalUnlock(hpxldata);<br />
	DWORD size = GlobalSize(hpxldata);<br />
	HGLOBAL h = GlobalFree(hpxldata);<br />
	DeleteObject(hmemBM);<br />
	DeleteDC(hmemDC);<br />
	ReleaseDC(0,hScreenDC);<br />
	return ;


The new image need to be same in file size, resolution, bpp except the modification in image data. Kindly help.

Thanks

~Vini
QuestionHow can I change a menu item when I click? Pin
lillah1-Nov-04 22:58
lillah1-Nov-04 22:58 
AnswerRe: How can I change a menu item when I click? [Modified] Pin
Antony M Kancidrowski2-Nov-04 1:32
Antony M Kancidrowski2-Nov-04 1:32 
GeneralactiveX Pin
hou_1261-Nov-04 22:48
hou_1261-Nov-04 22:48 
GeneralSystem tray colors Pin
Anonymous1-Nov-04 21:52
Anonymous1-Nov-04 21:52 
GeneralRe: System tray colors Pin
RChin1-Nov-04 22:19
RChin1-Nov-04 22:19 
GeneralRe: System tray colors Pin
Selvam R2-Nov-04 2:40
professionalSelvam R2-Nov-04 2:40 
GeneralRe: System tray colors Pin
ThatsAlok3-Nov-04 17:59
ThatsAlok3-Nov-04 17:59 
QuestionHow to define an array of the object in class Pin
Cramp1-Nov-04 21:48
Cramp1-Nov-04 21:48 
AnswerRe: How to define an array of the object in class Pin
Cedric Moonen1-Nov-04 21:55
Cedric Moonen1-Nov-04 21:55 
AnswerRe: How to define an array of the object in class Pin
Maximilien2-Nov-04 2:42
Maximilien2-Nov-04 2:42 
GeneralThumbnail view and Drag and Drop Pin
phieu1-Nov-04 21:36
phieu1-Nov-04 21:36 
GeneralRe: Thumbnail view and Drag and Drop Pin
Selvam R2-Nov-04 2:45
professionalSelvam R2-Nov-04 2:45 
GeneralEnable Combo Pin
balajeedurai1-Nov-04 21:17
balajeedurai1-Nov-04 21:17 
QuestionSDI Main Frame positioning? Pin
kriaz1-Nov-04 19:21
kriaz1-Nov-04 19:21 
QuestionHow to retrieve public folders list in an exchange server Pin
lavanm1-Nov-04 18:45
lavanm1-Nov-04 18:45 
QuestionHow to create Web Interface using MFC Program Pin
pubududilena1-Nov-04 18:16
pubududilena1-Nov-04 18:16 
AnswerRe: How to create Web Interface using MFC Program Pin
alex.barylski1-Nov-04 20:00
alex.barylski1-Nov-04 20:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.