I am supposed to load an image from a file and this image should cover 80% of pictureBox and then draw something on it… With loading there is no problem, but trying to draw anything on it drops an error that has an unproper parameter (g.FillRectangle…).
I found on stack advice to refresh pictureBox, but it changes nothing…
And i have no idea how to solve this…
private void button1_Click_1(object sender, EventArgs e)
{
pictureBox1.Width = (int)(Width * 0.80);
pictureBox1.Height = (int)(Height * 0.80);
// open file dialog
OpenFileDialog open = new OpenFileDialog();
// image filters
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
// display image in picture box
pictureBox1.Image = new Bitmap(open.FileName);
// image file path
// textBox1.Text = open.FileName;
g.FillRectangle(Brushes.Red, 0, 0, 20, 50);
pictureBox1.Refresh();
}
}
Use
Graphics.FromImageorControl.CreateGraphicsmethods for draw on your image:or draw directly on
PictureBoxbyPaintevent (for example by usingAnonymous Methods):