Using Visual Studio C#. I want to save the image inside my PictureBox as a .png using SaveFileDialog, but whenever I try to, I keep getting NullReferenceException at the last line. I can't seem to figure out what's causing this and how to fix it.
private void button_Save_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "PNG(*.PNG)|*.png";
if (sfd.ShowDialog() == DialogResult.OK)
pictureBox.Image.Save(sfd.FileName, ImageFormat.Png);
}