Bitmap.MakeTransparent OutOfMemoryException

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Whenever I use this method I get out of memory exception, even when using tiny bitmaps (100X100)
Does anyone know why this is
From what I remember OutOfMemory Exception is a default for other exceptions, does anyone know what it might be
I am of course using try catch and finally blocks to ensure in cases of exceptions resources get released, I just can't understand why i'm always getting this exception

Help me people of the newsgroups, you're my only hope

jax
 
Can you post code that demonstrates this? It seems to be working fine for
me.

--
Bob Powell [MVP]
C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

Jax said:
Whenever I use this method I get out of memory exception, even when using tiny bitmaps (100X100).
Does anyone know why this is?
From what I remember OutOfMemory Exception is a default for other
exceptions, does anyone know what it might be?
I am of course using try catch and finally blocks to ensure in cases of
exceptions resources get released, I just can't understand why i'm always
getting this exception.
 
It's as simple as:

(psuedo)
FileStream fs = new FileStream(@"c:\myImage.bmp", FileMode.Open);
Bitmap b = Bitmap.FromStream(fs);
try
{
Label theColour= new Label();
// client side script where the user clicks the image
int x = Convert.ToInt32(TextBox1.Text);
int y = Convert.ToInt32(TextBox2.Text);
theColour.BackColour = b.GetPixel(x,y);
b.MakeTransparent(theColour.BackColor); // Error here, OutOfMemoryException
b.SaveAs(fs, ImageFormat.Jpeg); // Occasionally error here, unspecified.
Image1.Url = "c:\myImage.Jpg";
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}
finally
{
b.Dispose();
fs.Close();
}
 
Back
Top