Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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>

..::[ kleptos ]::..
  • *Experts*
Posted

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.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

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>

..::[ kleptos ]::..

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...