![]() |
|
|
|||||||
![]() |
ASP Net - generation of PNG in asp.net failed |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
<%@ Page Language = "VB" ContentType="image/Png" %>
<%@ Import Namespace = "System.Drawing"%> <%@ Import Namespace = "System.Drawing.Imaging"%> <%@ Import Namespace = "System.Drawing.Drawing2D"%> <% Response.Clear() Dim height As integer = 100 Dim width As integer = 200 Dim bmp As New Bitmap(width, height, PixelFormat.Format24bppRgb) Dim g As Graphics = Graphics.FromImage(bmp) g.SmoothingMode = SmoothingMode.AntiAlias g.Clear(Color.White) g.FillRectangle(New SolidBrush(Color.LightGray), 1, 1, 150, 50) g.DrawString("Zone", New Font("Verdana", 10), SystemBrushes.WindowText, New PointF(10, 15)) bmp.Save(Response.OutputStream, ImageFormat.Png) g.Dispose() bmp.Dispose() Response.End() %> Error Msg Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. I wonder if i could generate png in asp.net by using "Dim bmp As New Bitmap(width, height, PixelFormat.Format24bppRgb)" that? If not so, what i should use? Thank you. Regards, Angus angus |
|
|
|
|
#2 |
|
Posts: n/a
|
What if you "g.dispose" before saving ?
Patrice "angus" <> a écrit dans le message de news:... > <%@ Page Language = "VB" ContentType="image/Png" %> > <%@ Import Namespace = "System.Drawing"%> > <%@ Import Namespace = "System.Drawing.Imaging"%> > <%@ Import Namespace = "System.Drawing.Drawing2D"%> > > <% > Response.Clear() > Dim height As integer = 100 > Dim width As integer = 200 > > Dim bmp As New Bitmap(width, height, PixelFormat.Format24bppRgb) > Dim g As Graphics = Graphics.FromImage(bmp) > > g.SmoothingMode = SmoothingMode.AntiAlias > g.Clear(Color.White) > g.FillRectangle(New SolidBrush(Color.LightGray), 1, 1, 150, 50) > g.DrawString("Zone", New Font("Verdana", 10), SystemBrushes.WindowText, New > PointF(10, 15)) > > bmp.Save(Response.OutputStream, ImageFormat.Png) > g.Dispose() > bmp.Dispose() > Response.End() > > %> > > Error Msg > Exception Details: System.Runtime.InteropServices.ExternalException: A > generic error occurred in GDI+. > > I wonder if i could generate png in asp.net by using "Dim bmp As New > Bitmap(width, height, PixelFormat.Format24bppRgb)" that? > > If not so, what i should use? > > Thank you. > > Regards, > Angus > > Patrice |
|
|
|
#3 |
|
Posts: n/a
|
the same error happened also.
by the way, if i changed > > bmp.Save(Response.OutputStream, ImageFormat.Png) to bmp.Save(Response.OutputStream, ImageFormat.Jpeg) as well as change the contenttype to "contenttype='image/jpeg' every thing works fine. "Patrice" <> wrote in message news:... > What if you "g.dispose" before saving ? > > Patrice > > > "angus" <> a écrit dans le message de > news:... > > <%@ Page Language = "VB" ContentType="image/Png" %> > > <%@ Import Namespace = "System.Drawing"%> > > <%@ Import Namespace = "System.Drawing.Imaging"%> > > <%@ Import Namespace = "System.Drawing.Drawing2D"%> > > > > <% > > Response.Clear() > > Dim height As integer = 100 > > Dim width As integer = 200 > > > > Dim bmp As New Bitmap(width, height, PixelFormat.Format24bppRgb) > > Dim g As Graphics = Graphics.FromImage(bmp) > > > > g.SmoothingMode = SmoothingMode.AntiAlias > > g.Clear(Color.White) > > g.FillRectangle(New SolidBrush(Color.LightGray), 1, 1, 150, 50) > > g.DrawString("Zone", New Font("Verdana", 10), SystemBrushes.WindowText, > New > > PointF(10, 15)) > > > > bmp.Save(Response.OutputStream, ImageFormat.Png) > > g.Dispose() > > bmp.Dispose() > > Response.End() > > > > %> > > > > Error Msg > > Exception Details: System.Runtime.InteropServices.ExternalException: A > > generic error occurred in GDI+. > > > > I wonder if i could generate png in asp.net by using "Dim bmp As New > > Bitmap(width, height, PixelFormat.Format24bppRgb)" that? > > > > If not so, what i should use? > > > > Thank you. > > > > Regards, > > Angus > > > > > > angus |
|
|
|
#4 |
|
Posts: n/a
|
I made a search about this weird issue and found that according to
http://www.c-sharpcorner.com/Code/20...orkWithPNG.asp the PNG file format requires a seekable stream... "angus" <> a écrit dans le message de news:... > the same error happened also. > > by the way, if i changed > > > > bmp.Save(Response.OutputStream, ImageFormat.Png) > > to > > bmp.Save(Response.OutputStream, ImageFormat.Jpeg) > as well as change the contenttype to "contenttype='image/jpeg' > > every thing works fine. > > > "Patrice" <> wrote in message > news:... > > What if you "g.dispose" before saving ? > > > > Patrice > > > > > > "angus" <> a écrit dans le message de > > news:... > > > <%@ Page Language = "VB" ContentType="image/Png" %> > > > <%@ Import Namespace = "System.Drawing"%> > > > <%@ Import Namespace = "System.Drawing.Imaging"%> > > > <%@ Import Namespace = "System.Drawing.Drawing2D"%> > > > > > > <% > > > Response.Clear() > > > Dim height As integer = 100 > > > Dim width As integer = 200 > > > > > > Dim bmp As New Bitmap(width, height, PixelFormat.Format24bppRgb) > > > Dim g As Graphics = Graphics.FromImage(bmp) > > > > > > g.SmoothingMode = SmoothingMode.AntiAlias > > > g.Clear(Color.White) > > > g.FillRectangle(New SolidBrush(Color.LightGray), 1, 1, 150, 50) > > > g.DrawString("Zone", New Font("Verdana", 10), SystemBrushes.WindowText, > > New > > > PointF(10, 15)) > > > > > > bmp.Save(Response.OutputStream, ImageFormat.Png) > > > g.Dispose() > > > bmp.Dispose() > > > Response.End() > > > > > > %> > > > > > > Error Msg > > > Exception Details: System.Runtime.InteropServices.ExternalException: A > > > generic error occurred in GDI+. > > > > > > I wonder if i could generate png in asp.net by using "Dim bmp As New > > > Bitmap(width, height, PixelFormat.Format24bppRgb)" that? > > > > > > If not so, what i should use? > > > > > > Thank you. > > > > > > Regards, > > > Angus > > > > > > > > > > > > Patrice |
|
|
|
#5 |
|
Posts: n/a
|
MemoryStream io = new MemoryStream();
bmp.Save(io, ImageFormat.Png); Response.BinaryWrite( io.GetBuffer() ); "Patrice" <> wrote in message news:... > I made a search about this weird issue and found that according to > http://www.c-sharpcorner.com/Code/20...orkWithPNG.asp the PNG file > format requires a seekable stream... > > > "angus" <> a écrit dans le message de > news:... > > the same error happened also. > > > > by the way, if i changed > > > > > > bmp.Save(Response.OutputStream, ImageFormat.Png) > > > > to > > > > bmp.Save(Response.OutputStream, ImageFormat.Jpeg) > > as well as change the contenttype to "contenttype='image/jpeg' > > > > every thing works fine. > > > > > > "Patrice" <> wrote in message > > news:... > > > What if you "g.dispose" before saving ? > > > > > > Patrice > > > > > > > > > "angus" <> a écrit dans le message de > > > news:... > > > > <%@ Page Language = "VB" ContentType="image/Png" %> > > > > <%@ Import Namespace = "System.Drawing"%> > > > > <%@ Import Namespace = "System.Drawing.Imaging"%> > > > > <%@ Import Namespace = "System.Drawing.Drawing2D"%> > > > > > > > > <% > > > > Response.Clear() > > > > Dim height As integer = 100 > > > > Dim width As integer = 200 > > > > > > > > Dim bmp As New Bitmap(width, height, PixelFormat.Format24bppRgb) > > > > Dim g As Graphics = Graphics.FromImage(bmp) > > > > > > > > g.SmoothingMode = SmoothingMode.AntiAlias > > > > g.Clear(Color.White) > > > > g.FillRectangle(New SolidBrush(Color.LightGray), 1, 1, 150, 50) > > > > g.DrawString("Zone", New Font("Verdana", 10), > SystemBrushes.WindowText, > > > New > > > > PointF(10, 15)) > > > > > > > > bmp.Save(Response.OutputStream, ImageFormat.Png) > > > > g.Dispose() > > > > bmp.Dispose() > > > > Response.End() > > > > > > > > %> > > > > > > > > Error Msg > > > > Exception Details: System.Runtime.InteropServices.ExternalException: A > > > > generic error occurred in GDI+. > > > > > > > > I wonder if i could generate png in asp.net by using "Dim bmp As New > > > > Bitmap(width, height, PixelFormat.Format24bppRgb)" that? > > > > > > > > If not so, what i should use? > > > > > > > > Thank you. > > > > > > > > Regards, > > > > Angus > > > > > > > > > > > > > > > > > > > > Hans Kesting |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| viewstate MAC failed in asp.net 2.0 while postback the page | azraffarveen | Software | 0 | 05-12-2009 03:24 PM |
| ASP.NET: Asign Users in Roles(Array.IndexOf(Of String) method) | msandlana | Software | 0 | 04-25-2008 06:37 AM |
| ASP.NET 2.0 application does not run in WIN2k3 | johnfraj | Software | 0 | 04-19-2007 08:27 AM |
| As growth slows, Hollywood faces a DVD standoff. | Allan | DVD Video | 0 | 07-11-2005 02:10 PM |
| Second Generation Blu-ray Products To Be Rolled Out At Year's End. | Allan | DVD Video | 0 | 03-16-2005 10:18 AM |