locked
Draw points RRS feed

  • Question

  • Hello everyone, if I have to draw several points without joining them, how can i do it ?

    Thanks for your help

    Wednesday, January 24, 2007 9:39 AM

Answers

  • See SetPixel method in MSDN, simply provide a color, x and y coordinates and it'll give that particular pixel the color you specified and then draw the image.

    Here is an example from MSDN itself

    public void SetPixel_Example(PaintEventArgs e)
    {
                 
        // Create a Bitmap object from a file.
        Bitmap myBitmap = new Bitmap("Grapes.jpg");
                 
        // Draw myBitmap to the screen.
        e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width,
            myBitmap.Height);
                 
        // Set each pixel in myBitmap to black.
        for (int Xcount = 0; Xcount < myBitmap.Width; Xcount++)
        {
            for (int Ycount = 0; Ycount < myBitmap.Height; Ycount++)
            {
                myBitmap.SetPixel(Xcount, Ycount, Color.Black);
            }
        }
                 
        // Draw myBitmap to the screen again.
        e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0,
            myBitmap.Width, myBitmap.Height);
    }
    I hope this will help.
    Best Regards,
    Rizwan aka RizwanSharp
    Wednesday, January 24, 2007 7:20 PM

All replies

  • See SetPixel method in MSDN, simply provide a color, x and y coordinates and it'll give that particular pixel the color you specified and then draw the image.

    Here is an example from MSDN itself

    public void SetPixel_Example(PaintEventArgs e)
    {
                 
        // Create a Bitmap object from a file.
        Bitmap myBitmap = new Bitmap("Grapes.jpg");
                 
        // Draw myBitmap to the screen.
        e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width,
            myBitmap.Height);
                 
        // Set each pixel in myBitmap to black.
        for (int Xcount = 0; Xcount < myBitmap.Width; Xcount++)
        {
            for (int Ycount = 0; Ycount < myBitmap.Height; Ycount++)
            {
                myBitmap.SetPixel(Xcount, Ycount, Color.Black);
            }
        }
                 
        // Draw myBitmap to the screen again.
        e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0,
            myBitmap.Width, myBitmap.Height);
    }
    I hope this will help.
    Best Regards,
    Rizwan aka RizwanSharp
    Wednesday, January 24, 2007 7:20 PM
  • Thank u very much for ur help Rizwan

     

    Wednesday, January 24, 2007 7:36 PM
  • Did you try that?

    Best Regards,

    Rizwan aka RizwanSharp

    Thursday, January 25, 2007 2:36 PM