Bitmap.Save() Invalid Parameter Used

By | April 8, 2006

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 12 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’s mind leveraging geographically dispersed team members.

5 thoughts on “Bitmap.Save() Invalid Parameter Used

  1. Wendy

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

  2. JayvardhanPune

    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

Leave a Reply

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