Hi,
I am trying to display a Png image via ASP .NET. I get the image from the
stream, creates the Bitmap, set the content type to Image/Png, but it give an
error. If I set the content type to Image/Jpeg it works really fine. Below is
the code I wrote and the error msg:
************************************************** ********
ERROR
************************************************** ********
A generic error occurred in GDI+.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.ExternalException: A
generic error occurred in GDI+.
Source Error:
Line 27: // makeTransparent((float)Double.Parse(trans));
Line 28:
Line 29: b.Save(Response.OutputStream, ImageFormat.Png);
Line 30: }
Line 31:
Source File: c:\inetpub\wwwroot\ImageGenerator\ImgGen.aspx Line: 29
Stack Trace:
[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder,
EncoderParameters encoderParams) +631
System.Drawing.Image.Save(Stream stream, ImageFormat format) +34
ASP.ImgGen_aspx.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\ImageGenerator\ImgGen.aspx:29
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
************************************************** ********
I have given full permission to "Everyone" as I heard it is a permission
problem, but no success. Following is the piece of code that I wrote:
************************************************** ********
CODE
************************************************** ********
<%@ Page language="c#" Debug="true" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<script language="C#" runat="server">
Bitmap b = null;
Graphics g = null;
void Page_Load(Object sender, EventArgs e)
{
Response.ContentType = "image/jpeg";
string url = Request.QueryString["url"];
string trans = Request.QueryString["trans"];
WebClient client = new WebClient();
Stream stream = client.OpenRead(url);
b = new Bitmap(stream);
// stream.Close(); // I TRIED AN UN-COMMENTED VERSION TOO
b.Save(Response.OutputStream, ImageFormat.Png);
}
</script>
************************************************** ********
Please note that if I change the content type to Image/Jpeg, it works
perfect. If any one can help, that would be appreciated.
Thanx,
Fahad