Resizing picture C#
<p>need help. i want to resize a certain picture but when i run this code it give me the error {"A generic error occurred in GDI+."}</p>

<pre><code> private void btnPic_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Filter = "Images|*.bmp;*.jpg;*.gif|All files|*.*";

            if (open.ShowDialog(this) == DialogResult.OK)
            {

                 var image = Image.FromFile(open.FileName);
                 var newImage = ScaleImage(image, 300, 400);
                 newImage.Save(@open.FileName, ImageFormat.Png);

            }
}


 public static Image ScaleImage(Image image, int maxWidth, int maxHeight)
        {
            var ratioX = (double)maxWidth / image.Width;
            var ratioY = (double)maxHeight / image.Height;
            var ratio = Math.Min(ratioX, ratioY);

            var newWidth = (int)(image.Width * ratio);
            var newHeight = (int)(image.Height * ratio);

            var newImage = new Bitmap(newWidth, newHeight);
            Graphics.FromImage(newImage).DrawImage(image, 0, 0, newWidth, newHeight);
            return newImage;
        }
</code></pre>
