Image Transparency in ASP.NET

G

Guest

I have developed a form application in C# that makes the image transparent by
changing the alpa value in the image color matrix. It work perfect. I am
using the same algorithm with ASP.NET but this does not work. There is no
sytactical problem. But I am not able to figure out the reason. Can any one
plz help me in this. Following is my ASP .NET code:

/*******************************************************/

<%@ Page language="c#" Debug="true" %> <!-- CodeBehind="ImgGen.aspx.cs"
AutoEventWireup="false" Inherits="ImgageGenerator.ImgGen" %> <!--
Codebehind="ImgGen.aspx.cs" AutoEventWireup="false"
Inherits="ImgageGenerator.ImgGen" -->
<%@ 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"];

// Response.Write("url: "+url);
// Response.Write("<br>trans: "+(float)Double.Parse(trans));

WebClient client = new WebClient();
Stream stream =
client.OpenRead(url);//"http://www.n-tv.de/images/200410/5438283_angelina-jolie8.jpg");
b = new Bitmap(stream);

makeTransparent((float)Double.Parse(trans));

b.Save(Response.OutputStream, ImageFormat.Jpeg);
}

void makeTransparent(float transparencyLevel)
{
ColorMatrix clrMatrix = new ColorMatrix();
clrMatrix.Matrix33 = transparencyLevel;

ImageAttributes imgAtt = new ImageAttributes();
imgAtt.SetColorMatrix(clrMatrix);

// Response.Write("<br>clrMatrix.Matrix33: "+clrMatrix.Matrix33);

g = Graphics.FromImage(b);
g.DrawImage(b, new Rectangle(385, 30, b.Width, b.Height), 0, 0,
b.PhysicalDimension.Width, b.PhysicalDimension.Height, GraphicsUnit.Pixel,
imgAtt);
// g.Dispose();

// Response.Write("<br>b: "+b);
}
</script>

/*******************************************************/


Kind Regards,

Fahad
 
C

Chris Simmons

On Fri, 3 Dec 2004 06:49:07 -0800, "Fahad Aijaz" <Fahad
I have developed a form application in C# that makes the image transparent by
changing the alpa value in the image color matrix. It work perfect. I am
using the same algorithm with ASP.NET but this does not work. There is no
sytactical problem. But I am not able to figure out the reason. Can any one
plz help me in this. Following is my ASP .NET code:
<SNIP>
{
Response.ContentType = "image/jpeg";
<SNIP>

I don't think JPEG supports transparency, does it?
 
G

Guest

Yes Chris it does support transparancy... As I told earlier as well... the
same algorithm works perfect on C# form application. I am successfull in
making the JPEG transparent there.
 
C

Chris Simmons

Yes Chris it does support transparancy... As I told earlier as well... the
same algorithm works perfect on C# form application. I am successfull in
making the JPEG transparent there.

Fahad:

I don't know how you previewed your image to see your transparency,
but all the information I've ever gotten on JPG is that it does not
support it. You may have seen transparency, but it most likely was
not a JPEG, which is what you are telling the browser to render with
the ContentType indicated. For the web, as in this case you request
help for ASP.NET, the only transparent options you have are .GIF and
..PNG (See http://www.htmlhelp.com/design/imageuse.htm#transparent),
and even PNGs are not fully supported (in my experience).
 
C

Chris Simmons

Yes Chris it does support transparancy... As I told earlier as well... the

Here are some more supporting links:
http://www.faqs.org/faqs/jpeg-faq/part1/section-12.html
http://cter.ed.uiuc.edu/gif-jpeg/ (See section on
Features->Transparency)
http://www.digicamhelp.com/digital-camera-image-formats/web-graphics-formats.htm

Bottom line is JPEGs cannot be made transparent. I'd recommend PNG
for web transparency, but like I said in my previous post, it's not
cleanly supported in browsers.
 
K

Kevin Spencer

A JPG cannot be transparent. Period. A GIF can have one transparent color,
and a PNG can have variable transparency. I don't know what your C# app did,
but I do know that JPGs cannot be transparent.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
 
B

bruce barker

a jpg can be drawn transparently (its just a bitmap), but no browser
supports this.

-- bruce (sqlwork.com)




| A JPG cannot be transparent. Period. A GIF can have one transparent color,
| and a PNG can have variable transparency. I don't know what your C# app
did,
| but I do know that JPGs cannot be transparent.
|
| --
| HTH,
| Kevin Spencer
| .Net Developer
| Microsoft MVP
| Neither a follower
| nor a lender be.
|
| | > Yes Chris it does support transparancy... As I told earlier as well...
the
| > same algorithm works perfect on C# form application. I am successfull in
| > making the JPEG transparent there.
| >
| > "Chris Simmons" schrieb:
| >
| > > On Fri, 3 Dec 2004 06:49:07 -0800, "Fahad Aijaz" <Fahad
| > > (e-mail address removed)> wrote:
| > >
| > > >I have developed a form application in C# that makes the image
| transparent by
| > > >changing the alpa value in the image color matrix. It work perfect. I
| am
| > > >using the same algorithm with ASP.NET but this does not work. There
is
| no
| > > >sytactical problem. But I am not able to figure out the reason. Can
any
| one
| > > >plz help me in this. Following is my ASP .NET code:
| > > ><SNIP>
| > > >{
| > > > Response.ContentType = "image/jpeg";
| > > ><SNIP>
| > >
| > > I don't think JPEG supports transparency, does it?
| > >
| > > --
| > > Thanks,
| > > Chris Simmons
| > > (e-mail address removed)
| > >
|
|
 
G

Guest

Yes bruce is right. This is what my applicationa actually does. It gets the
jpg image from the web into a stream, created a bitmap from the stream, makes
it transparent and displays it. It work fine but not with ASP .NET. Can it be
a browser problem? I am using IE 6.0.2900 with XP service pack 2.
 

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,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top