In my previous post of Bitmap.save(): A Generic Error Occurred in GDI+, I explained about the lock which the Bitmap object creates on the file. Now if by mistake we dispose the object before saving the image, there is no image to be saved and the error “Invalid Parameter Used” will be encountered. You can generate this error by following code.
Dim oBitmap As Bitmap
oBitmap = New Bitmap("c:\\example.jpg")
Dim oGraphic As Graphics
oGraphic = Graphics.FromImage(oBitmap)
Dim oBrush As New SolidBrush(Color.Black)
Dim ofont As New Font("Arial", 8 )
oGraphic.DrawString("Some text to write", ofont, oBrush, 10, 10)
' Here bitmap object is disposed before saving it.
oBitmap.Dispose()
oBitmap.Save("c:\\example.jpg",ImageFormat.Jpeg)
oGraphic.Dispose()
Leave a Reply