I want to create a transparent image (GIF format) at run time. From what
I have seen on the web, the only way to create a transparent image is to
use the GIF89a format.
At this time I am trying to create a circle to place around some text on my
web page.
I have created a "helper" ASPX page with a VB Code page to create my image
in. Here is the code snippet:
'my Page_Load Sub is not wrapped.
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim m_Stream As New System.IO.MemoryStream
Dim newImage As System.Drawing.Bitmap
Dim newGraphic As System.Drawing.Graphics
Dim tmpPen As System.Drawing.Pen
' Create Bitmap
newImage = New Bitmap(200, 200)
tmpPen = New System.Drawing.Pen(Brushes.Red, 10)
' Initialize Graphics Class
newGraphic = Graphics.FromImage(newImage)
newGraphic.Clear(Color.White)
newGraphic.DrawEllipse(tmpPen, 10, 10, 180, 180)
newImage.MakeTransparent(Color.White)
newImage.Save(m_Stream, System.Drawing.Imaging.ImageFormat.Gif())
' Display Bitmap
Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "image/gif"
Response.AddHeader("Content-Type", "application/unknown")
Response.AppendHeader("Content-Transfer-Encoding", "Binary")
Response.BinaryWrite(m_Stream.ToArray())
Response.End()
End Sub
and in my ASPX page, I load the image using the following:
<img src="PDFForm.aspx" style="Z-INDEX: 1100; LEFT: 100px; POSITION:
absolute; TOP: 100px">
When the image displays, I get a red circle with a black square background.
Is there a way to actually create a transparent GIF at run time?
I have tried the following to create a circular "window" within the image
by replacing the DrawEllipse command. No luck there.
newGraphic.FillEllipse(Brushes.Transparent, 10, 10, 180, 180)
I have tried the following to create a square "window" in the middle of the
image:
For X = 50 To 150
For Y = 50 To 150
newImage.SetPixel(X, Y, Color.Transparent)
Next
Next
I have even tried to use the above code, and setting the color to Green,
and then used this command:
newImage.MakeTransparent(Color.Green)
Help me! I am pulling out what is left of my hair.
(Boy, if you look at all of my questions that I have sent to this forum,
they all seem to deal with images. Is there a more appropriate "image"
forum out there?)
Thank you all,
Bryan Clauss
===================================
This list is hosted by DevelopMentor� http://www.develop.com
Some .NET courses you may be interested in:
Essential .NET: building applications and components with C#
November 29 - December 3, in Los Angeles
http://www.develop.com/courses/edotnet
View archives and manage your subscription(s) at http://discuss.develop.com