0

I am using this method to load the image to my picturebox:

private void asdToolStripMenuItem_Click(object sender, EventArgs e)
    {
        pictureBox1.Load(textBox1.Text);
        pictureBox1.Visible = true;
    }

The image is loaded perfectly, but when I apply any filter to the image I get error:

Object reference not set to an instance of an object.

So how can I connect my url loaded image to my filters of image processing like gray, RGB and more...

SimpleBeat
  • 747
  • 1
  • 10
  • 20

1 Answers1

0

You're getting a NullReferenceExceptionat the line

Bitmap gimage = new Bitmap(img);

because img has not been assigned a value. You need to give it a value when you load a new image, something like:

private void asdToolStripMenuItem_Click(object sender, EventArgs e)
{
    pictureBox1.Load(textBox1.Text);
    pictureBox1.Visible = true;
    img = new Bitmap(textBox1.Text); //Add this line.
}

I noticed you already had this line inside saveToolStripMenuItem_Click, but not inside asdToolStripMenuItem_Click

Edit: If you're loading a bitmap from a URL, you can't load directly into a bitmap object like you would for a pictureBox. Check out Download image and create bitmap to learn how to do it.

Community
  • 1
  • 1
Tee
  • 414
  • 2
  • 8
  • 19
  • i added this line : 'img = new Bitmap(textBox1.Text);' now i get this error: **The given path's format is not supported.** and the image not loaded already !! _if i dont add that line the image loaded but the filter not work_ – mohamed momo Apr 28 '17 at 14:45
  • what's the value of textBox1.Text? – Tee Apr 28 '17 at 15:24
  • i use url of img i use this : https://trends.google.com/trends/resources/2327917647-google-icon.png – mohamed momo Apr 28 '17 at 16:01
  • see the edit I made to the answer – Tee Apr 28 '17 at 17:48