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()
Vishal Monpara is a full stack Solution Developer/Architect with 13 years of experience primarily using Microsoft stack. He is currently working in Retail industry and moving 1’s and 0’s from geographically dispersed hard disks to geographically dispersed user leveraging geographically dispersed team members.