none
how do I assign a colour to particular point/pixel RRS feed

  • Question

  • In visual studio C# 2010 how do I assign a particular colour to an individual point/pixel
    Monday, July 16, 2012 8:41 PM

Answers

  • thank you for your reply.  I had thought that set pixel might br involved but I do not know how to use it.  I wish to set the pixel or point within the form I am using. Can you help with some code example.  Regards

    If it's on your own form, then paint the pixel using a 1 X 1 line or rectangle.  Use the graphics in the OnPaint method to do the painting.
    • Marked as answer by embellish Wednesday, July 18, 2012 10:18 PM
    Tuesday, July 17, 2012 10:40 PM
  • Depending upon where the pixel is, use the WinAPI or .NET SetPixel method.
    • Proposed as answer by Mike FengModerator Tuesday, July 17, 2012 10:53 AM
    • Marked as answer by embellish Wednesday, July 18, 2012 10:17 PM
    Monday, July 16, 2012 8:59 PM

All replies

  • Depending upon where the pixel is, use the WinAPI or .NET SetPixel method.
    • Proposed as answer by Mike FengModerator Tuesday, July 17, 2012 10:53 AM
    • Marked as answer by embellish Wednesday, July 18, 2012 10:17 PM
    Monday, July 16, 2012 8:59 PM
  • Overriding the OnPaint Method

    e.Graphics.FillRectangle(Brushes.Red, x, y, 1, 1);

    Tuesday, July 17, 2012 7:56 AM
  • private 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);
    }


    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    Tuesday, July 17, 2012 9:06 AM
  • thank you for your reply.  I had thought that set pixel might br involved but I do not know how to use it.  I wish to set the pixel or point within the form I am using. Can you help with some code example.  Regards
    Tuesday, July 17, 2012 10:29 PM
  • thank you for your reply.  I had thought that set pixel might br involved but I do not know how to use it.  I wish to set the pixel or point within the form I am using. Can you help with some code example.  Regards

    If it's on your own form, then paint the pixel using a 1 X 1 line or rectangle.  Use the graphics in the OnPaint method to do the painting.
    • Marked as answer by embellish Wednesday, July 18, 2012 10:18 PM
    Tuesday, July 17, 2012 10:40 PM