Thread: Ask about SetPixel, Lineto and Moveto

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    68

    Smile Ask about SetPixel, Lineto and Moveto

    I write these below program to draw a rectangle which have black frame. In the rectangle have 4 red points and I draw the line between 2 point. So I get the result as this picture http://www.geocities.com/ooosawaddee...intPicture.jpg

    In the picture the red point is very small and the line between point is not exactly straight. I want the larger red point and straight line. Do you know how to do that?


    Code:
    	pDC->SetMapMode(MM_TEXT);
    
    	// Paint white color as the background 
    	pDC->FillSolidRect(origin.x, origin.y, 2000, 2000, RGB(255,255,255));
    	
    	int cx = 5;
    	int cy = 5;	
    	
    	CPen pen, pen2;
    	pen.CreatePen(PS_SOLID,2, RGB(0,0,0));
    
    	pDC->SelectObject(&pen);
    
    	pDC->Rectangle(cx,cy,(cx +256), (cy + 192));
    	pDC->SetPixel(45,10, RGB(255,0,0));
    	pDC->SetPixel(47,9, RGB(255,0,0));
    	pDC->SetPixel(79,45, RGB(255,0,0));
    	pDC->SetPixel(46,120, RGB(255,0,0));
    
    	pen2.CreatePen(PS_SOLID,1, RGB(0,0,255));
    
    	pDC->SelectObject(&pen2);
    	pDC->MoveTo(45,10);
    	pDC->LineTo(79,45);

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    One pixel is one pixel, you can't change the size of it. What you could do is write a cluster of 3x3 pixels to simulate a bigger one.

    I don't know what you mean by "straight line" though. If you mean it is "pixelated" (the angle not being an even 45 degree), then there's not much you can do. There is a concept know as anti-aliasing which blurs the edges making it look smoother, but that is advanced (and nothing I know of).
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    You can try drawing some rects and filling them for larger "points". Or you can make your on function which will draw diamonds or what not. A pixel is a pixel, its pretty small. Also you can get rid of the aliasing with bi-linear filtering if you'd like but that's probably not within the scope of your project. However if you are interested you can find a lot of algorithms online.

Popular pages Recent additions subscribe to a feed