Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all.
I need to draw a thick line with SetPixel API. I search very, but can't find any open source algorithm (Bresenham algorithm is one pixel, murphy algorithm is for line with more than 3 pixel thick, ... ).
If you can please help me.
Notice that I can not use CPen and other facilities in windows. I should use SetPixel.
Excuse me for bad English.
Posted

If you're going to do it with SetPixel(), you're going to have a lot of trouble. That will stuck your program. This is GDI we are talking about, which is a device independent high level graphical API. GDI has a quite long pipeline when we call a GDI drawing function. No. of calls to a drawing function slows your program than what it actually does.

For Example, both of the following functions will do the same, but will act as differently. Try using both functions and see the difference. (1st function uses a one call to draw a rectangle, but the 2nd uses 1000*1000, which is 1,000,000 function calls to the same function over and over) :

C++
void DrawRect(HDC hdc)
{
	Rectangle(hdc, 0, 0, 1000, 1000);
}

void SetPixelRect(HDC hdc)
{
	int i,j;
	for(i=0; i<1000; i++)
	for(j=0; j<1000; j++)
	{
	SetPixel(hdc, i, j, RGB(0,0,0));
	}
}


It's always good to start things from the scratch. But for your purpose, GDI is not the best place. You need to code directly to the VGA to do so. Try google for that.
 
Share this answer
 
v2
Comments
Espen Harlinn 6-Jan-13 5:29am    
Good point
You already posted this question at http://www.codeproject.com/Messages/4465499/Thick-Line-Algorithm.aspx[^]; please do not post in multiple forums.
 
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