Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I read this toturial:http://www.runicsoft.com/bmp.cpp[^]. But i don't know how to use it.
I want everytime Left mouse down on my control, it will return int format: "RGB(R,G,B)".
But when i use it in container C#,it worked incorrectly.

My code:

C++
void CLoadImageXCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
	int x, y;
	long size;
	BYTE* Buffer = LoadBMP ( &x, &y, &size, "myBMP.bmp" );
	BYTE* aRGB =ConvertBMPToRGBBuffer(Buffer,x,y);
	delete[] Buffer;
	int index=point.x*x+point.y;		
	CString str;
	COLORREF clr= RGB(aRGB[index],aRGB[index+1],aRGB[index+2]);
	str.Format("!!!RGB(%d,%d,%d)",GetRValue(clr),GetGValue(clr),GetBValue(clr));
	delete[] aRGB;
	myClick(str);
	InvalidateControl();	
	COleControl::OnLButtonDown(nFlags, point);
}


Please sone help me.
I am newbie.
Thanks in advance.
Posted
Comments
Richard MacCutchan 5-Oct-15 4:17am    
You probably need to talk to the person who wrote the tutorial. The functions LoadBMP and ConvertBMPToRGBBuffer are not part of the standard Windows run-time, so it's anyone's guess what they do.
Tokia 5-Oct-15 4:38am    
could i ask you? when iload image into a temporary DC but when i use getPIXEL() it not work correctly. Instead of y=10 will get the value i want but the temp c gave y=15, i don't know why? i tried setmapmode but still can't get it. Please!!!
Richard MacCutchan 5-Oct-15 4:49am    
Sorry, I know nothing about the code or tutorial that you are using. You really need to contact the author.

1 solution

Sorry for asking here. But i have no time now.
C++
CString myfuntion(HWND hWnd,CDC* dc,CPoint point)
{	
	CString str;
	CBitmap bmpCOM;
	BITMAP bm;
	
	bmpCOM.LoadBitmap(IDB_ROKU);
	bmpCOM.GetBitmap(&bm);
	CDC dcMem;
	dcMem.CreateCompatibleDC(dc);
	dcMem.SelectObject(bmpCOM);
	HDC hdcMem=dcMem;
	COLORREF clr= GetPixel(hdcMem,point.x,point.y);
	str.Format("W:%d H:%d {X:%d Y=%d}RGB(%d,%d,%d)",bm.bmWidth,bm.bmHeight,point.x,point.y,GetRValue(clr),GetGValue(clr),GetBValue(clr));
	return str;
}

this is the code i wrote by my mind.
But when i used it, the Y axis is not right.
Instead of y=10, it became y=15 in temp DC.
I tried to solve 3 days but have no way.
PLEASE I BEG everyone.
this is where my life is end.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900