Transparent image with ButtonImageGadget()?

Just starting out? Need help? Post your questions and find answers here.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Transparent image with ButtonImageGadget()?

Post 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!
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

you can use icons with transparency
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

well, unless I get a icon program to use my 200x120 size images!
isn't there any other way? Please help!
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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)
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post 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]

:D
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

ts-soft, I have found a better program, it is also freeware, :D

look: http://gif.ceskyweb.cz/eng/gifex.htm


now, I have converted my images to icons, help me how to use them in ButtonImageGadget()??
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

[deutsch]
oh nein, ich hab ein kleines problem, guck mal auf dieses bild hier:
Image
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:
Image
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]
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

I have tested the iconeditor, its not so good as snicoedit. can't make icon in 200x120 pixels.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post 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.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

you can test this: EC_ImagePluginOLE
viewtopic.php?t=6005&postdays=0&postord ... e&start=45
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

thanks, but It doesn't have TRANSPARENT coloring, bad thing :(
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

Stilll needing help!

Fred, you have something??
andrasch
New User
New User
Posts: 9
Joined: Wed Sep 21, 2005 2:43 pm
Location: Germany

Post 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.
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Transparent image with ButtonImageGadget()?

Post 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().
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Post Reply