Page 1 of 2
Transparent image with ButtonImageGadget()?
Posted: Wed Oct 19, 2005 4:57 pm
by josku_x
Hellooooo!
I need a little help, I have been developing a paint program and I need to use ButtonImageGadget() command with it.. the problem is, I don't know how to use a transparent image with that command, and the bigger problem is, PB doesn't read GIf files!!! You can help me either to solve how to use transparent images in ButtonImageGadget() OR you can solve how to use GIF files WITH transparency without external DLL's
Thank you thank you thank you!
very very appreciated of any kind of help!
Posted: Wed Oct 19, 2005 5:05 pm
by ts-soft
you can use icons with transparency
Posted: Wed Oct 19, 2005 5:21 pm
by josku_x
well, unless I get a icon program to use my 200x120 size images!
isn't there any other way? Please help!
Posted: Wed Oct 19, 2005 5:41 pm
by ts-soft
josku_x wrote:well, unless I get a icon program to use my 200x120 size images!
SnicoEdit:
http://www.snidesoft.com/article.php?st ... 3045559857 (FreeWare)
Posted: Wed Oct 19, 2005 5:45 pm
by josku_x
Danke schön, du bist echt ein held, ich hoffe das du deutsch sprechst ;P
[english]thank you, bla bal blaa blaa [/english]

Posted: Wed Oct 19, 2005 5:50 pm
by josku_x
ts-soft, I have found a better program, it is also freeware,
look:
http://gif.ceskyweb.cz/eng/gifex.htm
now, I have converted my images to icons, help me how to use them in ButtonImageGadget()??
Posted: Wed Oct 19, 2005 6:02 pm
by ts-soft
josku_x wrote:
now, I have converted my images to icons, help me how to use them in ButtonImageGadget()??
Code: Select all
If OpenWindow(0,#CW_USEDEFAULT, #CW_USEDEFAULT, 200, 120, #PB_Window_SystemMenu, "IconTest")
Image = LoadImage(0, "your.ico")
If CreateGadgetList(WindowID(0))
ButtonImageGadget(0, 0, 0, 200, 120, Image)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
EndIf
Ich spreche deutsch, besser als englisch
I'm speaking german, not so bad as english
Posted: Wed Oct 19, 2005 6:33 pm
by josku_x
[deutsch]
oh nein, ich hab ein kleines problem, guck mal auf dieses bild hier:

wie du siehst, ist mein icon nicht ganz in der ButtinImageGadget(), und ich bin mir 100% sicher das ich die grüne farbe als durchsichtig gemacht habe... walfisch dreck!
[deutsch]
[english]
oh no, I have a little problem, look to this picture:

as you can see, my icon is not fully drawn in the ButtonImageGadget(), and I am 100% sure that the green color was set to transparent, whale dirt (:D)!
[/english][/url]
Posted: Wed Oct 19, 2005 7:54 pm
by ts-soft
I have tested the iconeditor, its not so good as snicoedit. can't make icon in 200x120 pixels.
Posted: Wed Oct 19, 2005 9:28 pm
by josku_x
well, is there ANY way to use TRANSPARENT gif files with ButtonImageGadget()??
Please help, FRED, please help me, you made this language, so you know maybe the best how to do this, thanks, very great thanks to all people.
Posted: Thu Oct 20, 2005 8:45 am
by ts-soft
Posted: Thu Oct 20, 2005 9:25 am
by josku_x
thanks, but It doesn't have TRANSPARENT coloring, bad thing

Posted: Thu Oct 20, 2005 10:40 am
by josku_x
Stilll needing help!
Fred, you have something??
Posted: Tue May 03, 2011 12:25 pm
by andrasch
Okay, it's a bit late to be a real help to the questioner..., but maybe someone else can make use of it.
This procedure adds "gif-like" transparency to any image (the source being BMP or any other by the image-library supported type) when creating the ButtonImageGadget:
Code: Select all
Procedure createButtonImageGadget(ButtonLeft, ButtonTop, ButtonWidth, ButtonHeight, IconImageNo, TransparentColorValue = 0, Flags = #Null)
; returns gadget-number if successful
; TransparentColorValue = 0 => no transparency, ButtonImageGadget() can/should be used directly
Define IconImageWidth, IconImageHeight
Define *PixelBuffer, *BufferCursor
Define i, j, ColorValue
Define ButtonNo
If IsImage(IconImageNo)
If TransparentColorValue
IconImageWidth = ImageWidth(IconImageNo)
IconImageHeight = ImageHeight(IconImageNo)
; creating buffer for icon-image
*PixelBuffer = AllocateMemory(IconImageWidth * IconImageHeight * SizeOf(Long))
If *PixelBuffer
; reading pixels into buffer while "analysing" them for transparency
If StartDrawing(ImageOutput(IconImageNo))
*BufferCursor = *PixelBuffer
For i = 0 To IconImageWidth - 1
For j = 0 To IconImageHeight - 1
ColorValue = Point(i, j)
If ColorValue = TransparentColorValue
ColorValue = 0 ; = RGBA(0, 0, 0, 0) => 100% transparency
Else
ColorValue | $FF000000 ; sets alpha-channel to 255 => no transparency
EndIf
PokeL(*BufferCursor, ColorValue)
*BufferCursor + SizeOf(Long)
Next
Next
StopDrawing()
FreeImage(IconImageNo)
; creating empty base-image for image-button
IconImageNo = CreateImage(#PB_Any, IconImageWidth, IconImageHeight, 32)
If IconImageNo
; writing buffered pixels to button-image
If StartDrawing(ImageOutput(IconImageNo))
DrawingMode(#PB_2DDrawing_AllChannels)
*BufferCursor = *PixelBuffer
For i = 0 To IconImageWidth - 1
For j = 0 To IconImageHeight - 1
Plot(i, j, PeekL(*BufferCursor))
*BufferCursor + SizeOf(Long)
Next
Next
StopDrawing()
; image-writing ready, button can be created
ButtonNo = ButtonImageGadget(#PB_Any, ButtonLeft, ButtonTop, ButtonWidth, ButtonHeight, ImageID(IconImageNo), Flags)
EndIf
EndIf
FreeMemory(*PixelBuffer)
EndIf
EndIf
Else
; no transparency used
ButtonNo = ButtonImageGadget(#PB_Any, ButtonLeft, ButtonTop, ButtonWidth, ButtonHeight, ImageID(IconImageNo), Flags)
EndIf
EndIf
ProcedureReturn ButtonNo
EndProcedure
Don't know, how fast it will be with big images, but for icon-like things I found it working alright.
Re: Transparent image with ButtonImageGadget()?
Posted: Tue May 03, 2011 1:23 pm
by c4s
@andrasch
Just as a side note: The alpha channel of Png images is supported now (since PB 4.40?!). So you can use the Png transparency for drawing etc. and of course the ButtonImageGadget().