Bitmap.Save() Invalid Parameter Used

In my previous post of 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.



5 responses to “Bitmap.Save() Invalid Parameter Used”

  1. David North Avatar
    David North

    Thanks so much – after much trawling of the web you showed me the light!

  2. gkgajjar Avatar

    cheer mate !! it helped ..


  3. Dan Avatar

    Thanks a lot for this blog! It helped me out 🙂

  4. JayvardhanPune Avatar

    I am getting a similar exception as stated below
    can you please let me know if this is one and the same?

    Also please let me know if you have encountered this before.

    I am facing a problem with my GDI++ code in C# control.

    Though i have tried many things from last 6 months, i am not able to get completely rid of this bug.

    Whenever the user is opening a window or closing a window, i’m get following exception.

    This is a very rare exception but it causes the whole application crash and has become a nigtmare for me. This usually encountered in a load test.

    This problem is more frequent on Citrix seemless client as compared to normal desktop environment.

    InnnerException: Invalid parameter used.

    Stack Trace: at System.Drawing.Region.GetHrgn(Graphics g)
    at System.Windows.Forms.Control.GetHRgn(Region region)
    at System.Windows.Forms.Control.OnHandleCreated(EventArgs e)
    at Syste

  5. Wendy Avatar

    I keep getting an error stating that the bitmap is invalid and the computer shuts down. What causes that?

Leave a Reply

Your email address will not be published. Required fields are marked *