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
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