This message was discovered on microsoft.public.dotnet.languages.csharp.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
| Jax |
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
|
|
|
| |
|
| |
| |
| Bob Powell [MVP] (VIP) |
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" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address... > Whenever I use this method I get out of memory exception, even when using tiny bitmaps (100X100). [Original message clipped]
getting this exception. [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Jax |
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(); }
|
|
|
| |
|
|
| |
| |
| John Fisher |
Hi, I was just hunting down an answer to the same problem. It turns out that the Bitmap files I was loading were created with a 256 color bit-depth. My windows system is running 32-bit color. So, I loaded the bitmap file, then created a new Bitmap of the same width and height, but using a Graphics instance created from the desktop window. This produced a bitmap with the same color depth as my system. After that, I copied the original bitmap into the new one (with the right color depth). The new bitmap allows me to successfully call MakeTransparent!!
Here's my code.
// Get the current desktop screen graphics. Graphics g = Graphics.FromHwnd(IntPtr.Zero); // Make a bitmap using that color depth. Bitmap bitmap = new Bitmap(originalbitmap.Width, originalbitmap.Height, g); // Clean up. g.Dispose(); // Start drawing on our new bitmap. g = Graphics.FromImage(bitmap); // Copy the loaded bitmap to the bitmap with proper screen depth. g.DrawImage(originalbitmap, 0, 0, bitmap.Width, bitmap.Height); // Clean up. g.Dispose();
// Now we can successfully make the bitmap transparent! bitmap.MakeTransparent(bitmap.GetPixel(0, 0));
-------------------------------- From: John Fisher
|
|
|
| |
|
| |
|
|
|
|
|
|
|