473,396 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

generation of PNG in asp.net failed

<%@ 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
Nov 18 '05 #1
4 1386
What if you "g.dispose" before saving ?

Patrice
"angus" <an***@angus.com> a écrit dans le message de
news:um**************@TK2MSFTNGP09.phx.gbl...
<%@ 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

Nov 18 '05 #2
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" <no****@nowhere.com> wrote in message
news:eh**************@TK2MSFTNGP09.phx.gbl... What if you "g.dispose" before saving ?

Patrice
"angus" <an***@angus.com> a écrit dans le message de
news:um**************@TK2MSFTNGP09.phx.gbl...
<%@ 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


Nov 18 '05 #3
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" <an***@angus.com> a écrit dans le message de
news:ef**************@TK2MSFTNGP12.phx.gbl...
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" <no****@nowhere.com> wrote in message
news:eh**************@TK2MSFTNGP09.phx.gbl...
What if you "g.dispose" before saving ?

Patrice
"angus" <an***@angus.com> a écrit dans le message de
news:um**************@TK2MSFTNGP09.phx.gbl...
<%@ 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



Nov 18 '05 #4
MemoryStream io = new MemoryStream();
bmp.Save(io, ImageFormat.Png);
Response.BinaryWrite( io.GetBuffer() );
"Patrice" <no****@nowhere.com> wrote in message news:Og**************@TK2MSFTNGP11.phx.gbl...
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" <an***@angus.com> a écrit dans le message de
news:ef**************@TK2MSFTNGP12.phx.gbl...
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" <no****@nowhere.com> wrote in message
news:eh**************@TK2MSFTNGP09.phx.gbl...
What if you "g.dispose" before saving ?

Patrice
"angus" <an***@angus.com> a écrit dans le message de
news:um**************@TK2MSFTNGP09.phx.gbl...
> <%@ 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
>
>



Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Skip Montanaro | last post by:
I updated the patch that supports PEP 304, "Controlling Generation of Bytecode Files" to apply cleanly against current CVS. I've tested it on Mac OS X (straight Unix build only). I'd appreciate...
4
by: | last post by:
Some time ago I installed VC# 2003, made a small generic project, compile with the allow unsafe flag and I get the error below: "error CS1577: Assembly generation failed -- Unexpected exception...
8
by: | last post by:
Wel, I am rebuilding the VC# 2002 project that I have deployment problems with the 2003 version, hoping this solves the problems, but now I encounter this wierd bug??? If I have the project, and...
2
by: slawrence | last post by:
Hi I am getting an error "Code generation for property 'SubCategoryId' failed. Error was 'Property accessor 'SubCategoryId' on object 'yyy.zzz' threw the following exception: 'Object reference...
0
by: slawrence | last post by:
Hi I am getting an error "Code generation for property 'SubCategoryId' failed. Error was 'Property accessor 'SubCategoryId' on object 'yyy.zzz' threw the following exception: 'Object reference...
1
by: Don | last post by:
I'm getting the following exception displayed in the task list at design time for my project: "Code generation for property 'Controls' failed. Error was: 'Object reference not set to an...
1
by: Dieter \(DDP\) | last post by:
Hello When i add new resource files to my usercontrol project and i compile the project a i get a error message in the event log Activation context generation failed for...
0
by: Andy B | last post by:
I added a LINQ classes (dbml) file to my web application project and drug a sql server database table from the server explorer onto the o/r designer. I saved and closed the designer after that. I...
0
zybernau
by: zybernau | last post by:
We have migrated the project source code from 1.1 frame work to 2.0 frame work now i am working in vs 2005 , while in designing mode ahen doing some changes to the control there's one message...
5
by: Jim | last post by:
I am trying to compile a demo from the XNA site and I get this error Error 1 Assembly generation failed -- Error emitting 'System.Runtime.InteropServices.GuidAttribute' attribute --'Incorrect...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.