kleptos Posted January 7, 2004 Posted January 7, 2004 I create an image with an aspx page and i want it to be transparent. I am pretty much just making a small rectangle image with some text on it. But the background needs to be transparent so all you see is the text, no background color. Any ideas or tutorials? Thanks! <%@ Import Namespace="System" %> <%@ Import Namespace="System.Drawing" %> <%@ Import Namespace="System.Drawing.Drawing2D" %> <%@ Import Namespace="System.Drawing.Imaging" %> <script language="C#" runat="server"> private void Page_Load(object sender, System.EventArgs e) { Bitmap bmp = new Bitmap(175, 60); Graphics g = Graphics.FromImage(bmp); Font f = new Font("Verdana", 9); SolidBrush b = new SolidBrush(Color.Black); float x = 5; float y = 5; string line1 = "My String Of Text"; g.DrawString(line1, f, b, x, y); Response.ContentType = "image/gif"; bmp.Save(Response.OutputStream, ImageFormat.Gif); Response.End(); f.Dispose(); b.Dispose(); g.Dispose(); bmp.Dispose(); } </script> Quote ..::[ kleptos ]::..
*Experts* Bucky Posted January 7, 2004 *Experts* Posted January 7, 2004 Sure. Fill the entire background with some color that wouldn't actually be used in the picture (I like to use lime green). Then do all your painting and call the MakeTransparent() method of the Bitmap, passing the color you filled the background with. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
kleptos Posted January 8, 2004 Author Posted January 8, 2004 I have tried that but i guess that doesnt work with a aspx page? I am sorta using this aspx page as an image so to speak. When i implement the code you spoke of above,it turns the background black. This should work with a aspx page right? <img src="image.aspx"> <%@ Import Namespace="System" %> <%@ Import Namespace="System.Drawing" %> <%@ Import Namespace="System.Drawing.Drawing2D" %> <%@ Import Namespace="System.Drawing.Imaging" %> <script language="C#" runat="server"> private void Page_Load(object sender, System.EventArgs e) { Bitmap bmp = new Bitmap(175, 60); Graphics g = Graphics.FromImage(bmp); Rectangle r = new Rectangle(0,0,175,60); Font f = new Font("Verdana", 9, FontStyle.Bold); SolidBrush b = new SolidBrush(txtColor); SolidBrush bg = new SolidBrush(Color.Brown); float x = 5; float y = 5; g.Clear(Color.Transparent); g.SmoothingMode = SmoothingMode.AntiAlias; string line1 = "String Goes Here"; g.FillRectangle(bg, r); g.DrawString(line1, f, b, x, y); bmp.MakeTransparent(Color.Brown); Response.ContentType = "image/gif"; bmp.Save(Response.OutputStream, ImageFormat.Gif); Response.End(); f.Dispose(); b.Dispose(); g.Dispose(); bmp.Dispose(); } </script> Quote ..::[ kleptos ]::..
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.