I have a problem-saving an image file using c# in Windows Forms App. Environment MS visual and windows 11.
Clip of code where exception appears.(I clipped what I believe is the involved part).
Expand|Select|Wrap|Line Numbers
- private void saveImage2()
- {
- if (System.IO.File.Exists(@"D:\bilder\temp.png"))
- System.IO.File.Delete(@"D:\bilder\temp.png");
- MG.bmp.Save(@"D:\bilder\temp.png", ImageFormat.Png); // exception appears at this line.
- // Dispose of the image files.
- // MG.bmp.Dispose();
- }
I use it every time I update image content and others.
Here is the exception text:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=ark
StackTrace:
at ark.Form1.saveImage2() in C:\Users\xxxxx\source\repos\bok\ark\Form1.cs:line 1150
Can someone kindly help me get the exception devil off my back after 5 hours of knocking my head?
Thank You.