我正在使用此方法将图片加载到我的图片框中:
private void asdToolStripMenuItem_Click(object sender, EventArgs e)
{
pictureBox1.Load(textBox1.Text);
pictureBox1.Visible = true;
}
图像加载完美,但当我对图像应用任何滤镜时,我收到错误:
对象引用未设置为对象的实例。
那么如何将我的网址加载图像连接到我的图像处理过滤器,如灰色,RGB等......
答案 0 :(得分:0)
您在第
行获得了NullReferenceException
Bitmap gimage = new Bitmap(img);
因为img
尚未分配值。加载新图像时需要给它一个值,如:
private void asdToolStripMenuItem_Click(object sender, EventArgs e)
{
pictureBox1.Load(textBox1.Text);
pictureBox1.Visible = true;
img = new Bitmap(textBox1.Text); //Add this line.
}
我注意到您已在saveToolStripMenuItem_Click
内部使用此行,但未在asdToolStripMenuItem_Click
修改:如果您从网址加载bitmap
,则无法像加载图片框一样直接加载到bitmap
对象中。查看Download image and create bitmap以了解如何操作。