Last post Sep 28, 2012 07:53 AM by TripleO
Mar 26, 2006 05:43 AM|Professor X|LINK
I have a big problem, i want to add some text on a png file and render that page to
be a png image file then i wrote down this code on page_load function, is that right?
void Page_Load(object sender,
Bitmap img = new
Graphics g = Graphics.FromImage(img);
new Font("tahoma", 12f),
Response.ContentType = "image/png";
catch (Exception x)
Response.Write("<b>Programmatically error:</b> " + x.Message +
second when i run the aspx file i got the erro :A generic error occurred in GDI+.
i don't know, so please any one help me
please its urgent [:)]
May 20, 2006 05:47 PM|Fredrik K|LINK
May 21, 2006 04:45 AM|Professor X|LINK
Can you provide the solution with a sample code please
May 21, 2006 05:22 AM|Fredrik K|LINK
May 22, 2006 03:36 AM|Professor X|LINK
Aug 25, 2006 11:36 AM|sbader|LINK
MemoryStream fixed me also.
Props Fredrik K.
Sep 30, 2006 07:58 AM|rmbrown|LINK
Nov 22, 2006 10:31 AM|chavasekhar|LINK
I am getting the same error. My exception handler is reporting this error and logging it to the database. I have my images in my database and reading them back to the memory stream. Once i got them into the memory stream, i am drawing them on the page.
But for some images (extention is .jpeg only) i am getting the above error. i dont know, whats wrong with those images. Look below my code.
Dim imgArray As Array = dt.Rows(photoIndex).Item("UNCPATH")
If (imgArray.Length > 0) Then
Dim mStream As New MemoryStream(imgArray, 0, (imgArray.Length() - 1))
mStream.Write(imgArray, 0, (imgArray.Length() - 1))
If mStream.Length() > 0 Then
Dim img As Image = Bitmap.FromStream(mStream, True)
If Not img Is Nothing Then
Based on the stack trace i could find out which line of the code is causing it. Its the Bitmap.FromStream(..) is causing it.
Do you have any clues on whats going wrong with those 'some photos'. While storing the images, we are not sure what kind of images(.jpg,.bmp,.png,.tiff etc) the users are uploading. I am deciding the type based on their extention.
Nov 23, 2006 02:39 AM|Fredrik K|LINK
I cannot see any obvious faults in your code, my immediate thought is that maybe some of the images your users upload are corrupted - or not images at all?
Instead of using the extention of the file to determine it's type (which can easilly be forged), I'd recommend reading the files content type instead (you can get that info from the FileUpload control). For example, a jpeg will have "image/jpeg" as content
type, and a png image will have "image/png" etc.
Apr 04, 2007 09:03 AM|bhav27|LINK
MemoryStream ms = new MemoryStream();
byte arrImage = ms.GetBuffer();
Jan 08, 2008 08:19 AM|arunvinoth|LINK
Memory stream should be properly closed & disposed after usage.
It'll cause the GDI + error ..
or it has to be used like
using (MemoryStream MS = new MemoryStream )
// your code here
because it'll close & dispose the object.
Feb 01, 2009 05:47 AM|MinaSamy|LINK
I had a similar problem and the solution was is to dispose the original bitmap after using it
Jan 28, 2010 10:31 AM|rbriers|LINK
Works perfectly, thanks Mr Fredrik K
Apr 26, 2010 01:00 AM|Yovav|LINK
Thank you for this post,
I had a case where a URL Rewrite was getting this error only on the hosting server (was fine locally)
Your code using the MemoryStream did the trick!
Sep 28, 2011 11:19 AM|Manoj Tambe|LINK
Thanks it's working for me.
Sep 28, 2011 11:21 AM|Manoj Tambe|LINK
Your Code Working for me
Sep 28, 2012 07:53 AM|TripleO|LINK
Had the same problem, this one fixed it, thanx!