Transparent GIF code?

Discussions on GFL SDK, the graphic library for reading and writing graphic files

Moderators: XnTriq, helmut, xnview

b.e.wilson
Posts: 26
Joined: Wed Mar 09, 2005 7:44 pm

Transparent GIF code?

Post 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
User avatar
Ithier
Posts: 47
Joined: Fri Nov 19, 2004 10:50 am
Location: Paris, France

Post 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).
b.e.wilson
Posts: 26
Joined: Wed Mar 09, 2005 7:44 pm

Post 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.
b.e.wilson
Posts: 26
Joined: Wed Mar 09, 2005 7:44 pm

Post by b.e.wilson »

Looks like LZW is free to use now: http://www.unisys.com/about__unisys/lzw
b.e.wilson
Posts: 26
Joined: Wed Mar 09, 2005 7:44 pm

Post 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
mindplay
Posts: 16
Joined: Wed Sep 21, 2005 9:30 am
Location: Denmark

Post 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