Home > ASP .Net > Bitmap.Save() Invalid Parameter Used

Bitmap.Save() Invalid Parameter Used

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()
Categories: ASP .Net Tags:
  1. Wendy
    November 29th, 2006 at 07:01 | #1

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

  2. JayvardhanPune
    February 21st, 2007 at 02:31 | #2

    I am getting a similar exception as stated belowcan 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

  3. Dan
    February 6th, 2008 at 06:09 | #3

    Thanks a lot for this blog! It helped me out :-)

  4. November 25th, 2008 at 13:05 | #4

    cheer mate !! it helped ..

    Thanks

  5. December 5th, 2008 at 09:03 | #5

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

  1. No trackbacks yet.