bitmap.save(filename) - A generic error occurred in GDI+.
-
I'm not very good at programing, and when i tries to save the bitmap to a file i get the "A generic error occurred in GDI+." what am i doing wrong? I wrote a smal app to demonstrate what my problem is. In the real app it modifies some exif data and are then supposed to save the file. Public Class frmSaveFile Private _bitmap As Bitmap Private _filename As String = "d:\husvagn.jpg" Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click _bitmap = New Bitmap(_filename) btnOpen.Enabled = False btnClose.Enabled = True End Sub Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click _bitmap.Save(_filename) btnClose.Enabled = False btnOpen.Enabled = True End Sub End Class
-
I'm not very good at programing, and when i tries to save the bitmap to a file i get the "A generic error occurred in GDI+." what am i doing wrong? I wrote a smal app to demonstrate what my problem is. In the real app it modifies some exif data and are then supposed to save the file. Public Class frmSaveFile Private _bitmap As Bitmap Private _filename As String = "d:\husvagn.jpg" Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click _bitmap = New Bitmap(_filename) btnOpen.Enabled = False btnClose.Enabled = True End Sub Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click _bitmap.Save(_filename) btnClose.Enabled = False btnOpen.Enabled = True End Sub End Class
It errors out because the original file is locked by the Bitmap object that you loaded the image into. You can get around it by loading the image using a FileStream instead. See this[^] MS KB article for a sample.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
It errors out because the original file is locked by the Bitmap object that you loaded the image into. You can get around it by loading the image using a FileStream instead. See this[^] MS KB article for a sample.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007