Page 1 of 1

transparent GIF problem

Posted: Mon Dec 05, 2005 2:48 pm
by mindplay
I'm trying to generate a transparent GIF with GFLax in ASP, but I've run into a problem. Let's say I do this:

Code: Select all

<%

Const AX_GIF = 2
Const AX_To8Colors = 8
Const AX_NoDither = 0
Const AX_ToColors = 0

BG = RGB(255,255,255)
FG = RGB(255,0,0)
Text = "This is a test"

Set Pic = Server.CreateObject("GflAx.GflAx")
Pic.EnableLZW = True

Pic.FontName = "Verdana"
Pic.FontSize = 36

W = Pic.GetTextWidth(Text)
H = Pic.GetTextHeight(Text)

Pic.NewBitmap W, H, BG
Pic.TextOut Text, 0, 0, FG

Pic.SaveFormat = AX_GIF
Pic.ChangeColorDepth AX_To8Colors, AX_NoDither, AX_ToColors
Pic.UseTransparency = True
Pic.MaskColor = Pic.GetColorAt(0,0)
Pic.SaveBitmap Server.MapPath("test.gif")

%>
<HTML>
<HEAD></HEAD>
<BODY><IMG SRC="test.gif"></BODY>
</HTML>
Look here for the result ... as you can see, the red color is masked out as transparent, but the color at (0,0) is white. I've checked that GetColorAt(0,0) returns FFFFFF - this is true. I also tried RGB(255,255,255) which gives the same result ... so the error must lie within the transparency/maskcolor/savebitmap functions?

Posted: Wed Dec 07, 2005 1:08 pm
by mindplay
Anybody else experienced this problem? Anyone know the cause, or know if there's any way to work around it?

Posted: Wed Dec 07, 2005 8:24 pm
by xnview
mindplay wrote:Anybody else experienced this problem? Anyone know the cause, or know if there's any way to work around it?
Ok, the problem is antialias!
Perhaps by adding a FontAntialias property will fixed the problem!

Posted: Thu Dec 08, 2005 8:35 am
by mindplay
I don't see how that could be the problem? it shouldn't matter what's in the image in the first place - since I convert it to 8 colours first, the image has a palette ... normally, when you create a transparent GIF, that's what you do - reduce to x number of colors, then pick the color you want to be transparent.

If I set a specific MaskColor, shouldn't it mask that color out? otherwise what's the point of having MaskColor? setting it doesn't seem to have any effect at all?

Posted: Thu Dec 08, 2005 10:27 am
by xnview
mindplay wrote:I don't see how that could be the problem? it shouldn't matter what's in the image in the first place - since I convert it to 8 colours first, the image has a palette ... normally, when you create a transparent GIF, that's what you do - reduce to x number of colors, then pick the color you want to be transparent.

If I set a specific MaskColor, shouldn't it mask that color out? otherwise what's the point of having MaskColor? setting it doesn't seem to have any effect at all?
But here you have not a text in red, zoom in...

Posted: Thu Dec 08, 2005 12:23 pm
by mindplay
Yes, the edge pixels are not full-intensity red - I also don't want those masked out, so that's not a problem. But look at the code:

Pic.MaskColor = Pic.GetColorAt(0,0)

The color at 0,0 is the background color, WHITE, FFFFFF ... not red.

So white should be masked out - not red.

But it doesn't seem to matter WHAT I set MaskColor to - white OR red, it always masks out the same thing ... this property doesn't seem to have any effect at all?

Posted: Thu Dec 08, 2005 2:15 pm
by xnview
mindplay wrote:Yes, the edge pixels are not full-intensity red - I also don't want those masked out, so that's not a problem. But look at the code:

Pic.MaskColor = Pic.GetColorAt(0,0)

The color at 0,0 is the background color, WHITE, FFFFFF ... not red.

So white should be masked out - not red.

But it doesn't seem to matter WHAT I set MaskColor to - white OR red, it always masks out the same thing ... this property doesn't seem to have any effect at all?
Ok, right. Send me your a PM with your email, and i'll send you a beta version.