generation of PNG in asp.net failed

A

angus

<%@ 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
 
A

angus

the same error happened also.

by the way, if i changed

to

bmp.Save(Response.OutputStream, ImageFormat.Jpeg)
as well as change the contenttype to "contenttype='image/jpeg'

every thing works fine.
 
H

Hans Kesting

MemoryStream io = new MemoryStream();
bmp.Save(io, ImageFormat.Png);
Response.BinaryWrite( io.GetBuffer() );
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top