Page 1 of 1

Transparent GIF code?

Posted: Thu Mar 31, 2005 6:43 pm
by b.e.wilson
I'm trying to make a ruler with a transparent background in .gif format.

Code: Select all

B = RGB(255,255,255) 'white
F = RGB(0,0,0) 'black
w = 800 'pixels
p= 100 'scale factor
set GflAx = Server.CreateObject("GflAx.GflAx")
GflAx.LineWidth = 1
GflAx.LineColor = F 'white
GflAx.FontName = Arial
GflAx.FontSize = 14
GflAx.UseTransparency = TRUE
GflAx.MaskColor = B
GflAx.NewBitmap w, 15, B 'width, height, background
GflAx.TextOut "cm",11,3,F
j=0
ppcm=100*96/254
for i = 1 to w step ppcm 'write the cm scale
  GflAx.DrawLine i,1,i,12
  GflAx.TextOut j,i+3,3,F
  if ppcm/10>5 then
    for k = i to i+ppcm step ppcm/10
      GflAx.DrawLine k,1,k,3
    next
  end if
  j=j+1
next
GflAx.ChangeColorDepth(4)
GflAx.SaveFormat = 3 '1=jpeg, 2=gif, 3=png
Response.ContentType = "image/png"
Response.BinaryWrite GflAx.SendBinary
Set GflAx = nothing
I can make a .png, but the file lacks transparency. When I try to make a .gif file I get an error that the format is not supported by the bitmap (or vice-verse, I can't remember, it errored when executing the .SaveFormat command)).

Can anyone see what I've done wrong, or offer some working code I could follow to find what I've done incorrectly?

Thanks,
Bruce

Posted: Fri Apr 01, 2005 9:00 am
by Ithier
I don't know about the transparency, but for the gif format, if you want to use it, you must activate the property EnableLZW before using it (and obtain a license from UNISYS).

Posted: Fri Apr 01, 2005 3:13 pm
by b.e.wilson
I am most grateful. That was the solution. Now to wangle me a license, or go back to .png's.

Transparency still doesn't work, though. I'll keep working on that.

Posted: Fri Apr 01, 2005 3:18 pm
by b.e.wilson
Looks like LZW is free to use now: http://www.unisys.com/about__unisys/lzw

Posted: Mon Apr 04, 2005 5:49 pm
by b.e.wilson
Aha! I got it to work. I needed to move all transparency information to a point after I reduced the number of colors. Here's the end of the code:

Code: Select all

GflAx.ChangeColorDepth(1)
GflAx.EnableLZW = TRUE 'needed to write a .gif
GflAx.SaveFormat = 2 '1=jpeg, 2=gif, 3=png
if bTransparent then
  GflAx.UseTransparency = TRUE
  GflAx.MaskColor = B 'this color becomes transparent
  GflAx.BackColor = B 'the alpha color used when blending is needed
end if
'Response.ContentType = "image/png"
Response.ContentType = "image/gif"
Response.BinaryWrite GflAx.SendBinary
Set GflAx = nothing

Posted: Tue Dec 06, 2005 1:34 pm
by mindplay
I'm trying to do the same thing, but I'm having less luck than you :(

Any chance you could take a look at this post and tell me what you think?

Thanks