Drawing on an image RRS feed

  • Question

  • User-1979505704 posted

    I have a variable objGraphics. I want to know if it is possible to draw a dot at a random position on the image.

    Can anyone help me with this? 

    Tuesday, October 10, 2006 4:11 PM


  • User1439985827 posted
    Sure, here is an example (Make sure the namespace System.Drawing is in your Using statements): 
    Bitmap bmp = new Bitmap("C:\\test.jpg");
    Random rng = new Random();
    Graphics g = Graphics.FromImage(bmp);
    int x = rng.Next(bmp.Width);
    int y = rng.Next(bmp.Height);
    g.FillEllipse(new System.Drawing.SolidBrush(Color.Red), x, y, 6, 6);
    bmp.Save("C:\\test1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
     This will draw a red circle on a random spot on an image.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 10, 2006 7:28 PM