This error is a bug in .NET, in .NET 2.0 SP1 it should be correct.
Try this (copying bitmap to a new bitmap and than save):
Main Topics
Browse All TopicsI am writing an ASP .NET applicaiton which creates thumbnails on the fly (code below).
It works ok with any type of file except bmp.
This is the line in which I get the error:
bmp.Save(Response.OutputSt
An the complete error is:
"A generic error occurred in GDI+."
Again, this only happends with bmp files (not with jpg or any other format).
Any ideas?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I changed the ImageFormat.Bmp for ImageFormat.Jpg and it seems to be working even with BMP's
I still have some issues.
My app is suposed to search my database (in which I have a list of over 120,000 file locations - no images, just the location of the file in my server) and create a thumbnail on the fly for each image found (based on the fileLocation).
The problem is that, if the user doesn't filter the information then we will have thousands of thumbnail being generated on the fly and, obviously, it takes for ever to display all thumbnails on the page.
Any idea how can I create the thumbnails faster?
ps: I am not saving images on my database because, as I said, there are thousands and I don't want to kill my server. So, I just save the file location and create the thumbnail on the fly.
Thanks Juan, i will google "ashx handler for thumbnails".
The reason why I am calling my garbage collector is because, even though I am disposing my objects, the source file stays open after generating my thumbnail and stays open until I close my page.
I have multiple users using my app so I ended up with bunch of open files (being used by my app) that were slowing my server too much.
Therefore, I had to call the garbage collector to be sure that the source file was closed.
Any other idea to handle this problem?
Yes, sure. You need to use using statements, as I mentioned in my first post. Your code would look like the snippet below.
Keep in mind that, in ASP.NET, the GC should NOT be called in the user code. Even more, is not needed if you properly dispose your resources by means of "Using" statements.
More about "using" statement: http://msdn.microsoft.com/
I know this issue is closed, but I had the same issue with outputting BMP files and here's the solution.
Instead of:
bmp.Save(Response.OutputSt
which doesn't work.
You can use:
Dim mstream As New MemoryStream
bmp.Save(mstream, ImageFormat.bmp)
Response.Clear()
Response.Buffer = True
Response.BinaryWrite(mstre
Response.End()
Response.Flush()
I hope this helps someone, it drove me nuts.
Business Accounts
Answer for Membership
by: Juan_BarreraPosted on 2008-12-04 at 12:39:53ID: 23099189
Hi there, have a look at the following links:
icrosoft.c om/Forums/ en-US/netf xbcl/ threa d/b15357f1 -ad9d-4c80 -9ec1-92c7 86cca4e6/
ttp://blog .vishalon. net/index. php/bitmap save-a-gen eric- error -occurred- in-gdi/
o, don't call the Garbage Collection yourself, just use "Using" statements wherever possible, so you make sure that the unmanaged underlying GDI objects are properly disposed.
http://social.msdn.m
h
Als