473,383 Members | 1,868 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,383 software developers and data experts.

Png Image display Problem

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
Nov 19 '05 #1
1 4657
Fahad Aijaz wrote:
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:


try changing the code a bit, so that you are not writing directly to the OutputStream:

MemoryStream io = new MemoryStream();
myBitmap.Save(io, ImageFormat.Png);
byte[] ba = io.GetBuffer();
Response.BinaryWrite(ba);

There was something (I forgot the exact details) about needing read/write access to that
stream, and MemoryStream provides that.

Hans Kesting
Nov 19 '05 #2

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

Similar topics

9
by: Maurizio Penna | last post by:
I, guys. I've embeded an image into a xml file, something like that: <display type="picture" mime="image/png" name = "mosaico6.png"> <!]> </display> Now, I want to display it with a XSL...
5
by: Chris Beall | last post by:
I'm displaying an image that is also a link against a black background. In Netscape 7.1, the current background color is displayed as a horizontal bar below the image. This allows :hover effects...
4
by: zborisau | last post by:
Hey good people, I've been given a problem to solve recently - and stuck with the solution for a good 4 days already. i have a link which leads to popup window. the purpose of that popup...
4
by: Kevin Myers | last post by:
Hello, Please forgive my reposting of this note with hopefully a more relevant subject line. On an Access 2000 form under Windows 2000 I would like to use a Kodak Image Edit Control to...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
3
by: den 2005 | last post by:
Hi everyone, Here is code working on..Trying to insert record with a column with Image or VarBinary datatype in sql database from a existing jpeg image file, then retrieve this image from...
7
by: fredo | last post by:
I've studied Eric Meyer's pure css popups, version two: http://meyerweb.com/eric/css/edge/popups/demo2.html which pops up an image when I roll over a text link. Now I want to pop up a large...
3
by: =?Utf-8?B?SlIx?= | last post by:
I would like to add text to an image. I have tried to use DrawString and it works on some images but on others it is very very small. I am pretty sure it has something to do with the size of the...
0
by: bindslind | last post by:
The script does most of what it's supposed to do, but I have what seems to be a simple problem that I can't figure out. When the page intitially loads the first page does not display images. The same...
11
by: Chris Beall | last post by:
See http://pages.prodigy.net/chris_beall/Demo/photo%20block%20experiments.html I've ended up with what seems like a rather complex structure for what I thought would be a somewhat simple...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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...

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.