Try the following code

Bitmap.save(): A generic error occurred in GDI+Dim oBitmap As Bitmap
Bitmap.save(): A generic error occurred in GDI+oBitmap 
= New Bitmap("c:\\example.jpg")
Bitmap.save(): A generic error occurred in GDI+
Dim oGraphic As Graphics
Bitmap.save(): A generic error occurred in GDI+oGraphic 
= Graphics.FromImage(oBitmap)
Bitmap.save(): A generic error occurred in GDI+
Dim oBrush As New SolidBrush(Color.Black)
Bitmap.save(): A generic error occurred in GDI+
Dim ofont As New Font("Arial"8)
Bitmap.save(): A generic error occurred in GDI+oGraphic.DrawString(
"Some text to write", ofont, oBrush, 1010)
Bitmap.save(): A generic error occurred in GDI+oBitmap.Save(
"c:\\example.jpg",ImageFormat.Jpeg)
Bitmap.save(): A generic error occurred in GDI+oBitmap.Dispose()
Bitmap.save(): A generic error occurred in GDI+oGraphic.Dispose()

You will get the above mentioned error:A generic error occurred in GDI+. This problem occurs because until the bitmap object is disposed, it creates a lock on the underlying image file. So you can save the newly generated file with different name but not overwrite the file because of lock. Now suppose you want to overwrite the file then create another bitmap from old bitmap. dispose the object of old bitmap, process new bitmap object and save the new bitmap object with original file name. The above chunk of code should be written in the following way.

Bitmap.save(): A generic error occurred in GDI+Dim oBitmap As Bitmap
Bitmap.save(): A generic error occurred in GDI+
Bitmap.save(): A generic error occurred in GDI+oBitmap 
= New Bitmap("c:\\example.jpg")
Bitmap.save(): A generic error occurred in GDI+
Dim oGraphic As Graphics
Bitmap.save(): A generic error occurred in GDI+
' Here create a new bitmap object of the same height and width of the image.
Bitmap.save(): A generic error occurred in GDI+
Dim bmpNew As Bitmap = New Bitmap(oBitmap.Width, oBitmap.Height)
Bitmap.save(): A generic error occurred in GDI+oGraphic 
= Graphics.FromImage(bmpNew)
Bitmap.save(): A generic error occurred in GDI+oGraphic.DrawImage(oBitmap, 
New Rectangle(00, _
Bitmap.save(): A generic error occurred in GDI+ bmpNew.Width, bmpNew.Height), 
00, oBitmap.Width, _
Bitmap.save(): A generic error occurred in GDI+oBitmap.Height, GraphicsUnit.Pixel)
Bitmap.save(): A generic error occurred in GDI+
' Release the lock on the image file. Of course, 
Bitmap.save(): A generic error occurred in GDI+'
 image from the image file is existing in Graphics object
Bitmap.save(): A generic error occurred in GDI+
oBitmap.Dispose()
Bitmap.save(): A generic error occurred in GDI+oBitmap 
= bmpNew
Bitmap.save(): A generic error occurred in GDI+
Bitmap.save(): A generic error occurred in GDI+
Dim oBrush As New SolidBrush(Color.Black)
Bitmap.save(): A generic error occurred in GDI+
Dim ofont As New Font("Arial"8)
Bitmap.save(): A generic error occurred in GDI+oGraphic.DrawString(
"Some text to write", ofont, oBrush, 1010)
Bitmap.save(): A generic error occurred in GDI+oGraphic.Dispose()
Bitmap.save(): A generic error occurred in GDI+ofont.Dispose()
Bitmap.save(): A generic error occurred in GDI+oBrush.Dispose()
Bitmap.save(): A generic error occurred in GDI+oBitmap.Save(
"c:\\example.jpg", ImageFormat.Jpeg)
Bitmap.save(): A generic error occurred in GDI+oBitmap.Dispose()

相关文章: