473,758 Members | 2,401 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 .ExternalExcept ion: 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\wwwr oot\ImageGenera tor\ImgGen.aspx Line: 29

Stack Trace:
[ExternalExcepti on (0x80004005): A generic error occurred in GDI+.]
System.Drawing. Image.Save(Stre am stream, ImageCodecInfo encoder,
EncoderParamete rs encoderParams) +631
System.Drawing. Image.Save(Stre am stream, ImageFormat format) +34
ASP.ImgGen_aspx .Page_Load(Obje ct sender, EventArgs e) in
c:\inetpub\wwwr oot\ImageGenera tor\ImgGen.aspx :29
System.Web.UI.C ontrol.OnLoad(E ventArgs e) +67
System.Web.UI.C ontrol.LoadRecu rsive() +35
System.Web.UI.P age.ProcessRequ estMain() +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="Syst em.Drawing" %>
<%@ Import Namespace="Syst em.Drawing.Imag ing" %>
<%@ Import Namespace="Syst em.Net" %>
<%@ Import Namespace="Syst em.IO" %>
<script language="C#" runat="server">
Bitmap b = null;
Graphics g = null;

void Page_Load(Objec t sender, EventArgs e)
{
Response.Conten tType = "image/jpeg";
string url = Request.QuerySt ring["url"];
string trans = Request.QuerySt ring["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 4679
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 .ExternalExcept ion: 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(i o, ImageFormat.Png );
byte[] ba = io.GetBuffer();
Response.Binary Write(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
9718
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 Transformation, but my code don't work: <display>
5
3486
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 that change the background color to have a visible effect, as this bar changes color. By default, it appears that the color is inherited from the body color, i.e. with no link style applied, the bar is black, and invisible against the background....
4
44087
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 window is to redirect user to the one of available servers. so i need to check which server is available. i have decided to download some 1pixel image from every server and if it was downloaded
4
8384
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 display the contents of a TIFF image file. According to the very limited documentation that I have been able to locate so far, all I should need to do is to drop the Image Edit Control onto the form in design mode, set the control's Image property to...
7
11638
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 is proving to be more difficult. These pictureboxes are bound to an AccessDB. If the user wants to add an image, they select an image using an OpenFileDialog: Dim result As DialogResult = Pic_Sel.ShowDialog() If (result = DialogResult.OK) Then
3
5242
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 database and display it in a Image web control dynamically(at runtime). The process after being displayed in the web control, user click insert/add button, it converts the image(jpeg) file to bytes and store it the database with Image or VarBinary...
7
27502
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 image when I roll over a thumbnail. I've tried some things, but can't make it work. See here (Warning: adult matter):
3
2525
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 image but I have had varying results on multiple images. Is there anyway to make the text a fixed size on the image. Similar to putting a date on a photograph.
0
2355
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 things happens when the "1" link is selected and ofcourse when "previous" is clicked from page 2. Other than this everything is a-ok. I think I just may need another set of eyes to check it out. Thanks. And here's the code: <?php ...
11
4999
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 problem. Even that complex solution works well only in FireFox (haven't tested Safari...). Can anyone come up with a better solution, where 'better' means: - Works as well as the example above, but is simpler. OR
0
9492
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9740
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8744
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7287
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6564
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5332
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3832
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.