image and Transparency ( to produce a layer with an image )

Share your advanced PureBasic knowledge/code with the community.
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

image and Transparency ( to produce a layer with an image )

Post by dobro »

to produce a layer with an image

on va donner l'impression que notre image est transparente en copiant ce qui se trouve sous l'image dans l'image (une copie d'ecran, dans notre image avant de poser celle-ci au même endroit )
notre image deviendra alors a nos yeux "transparente" ... :)
we will give the impression that our image is transparent by copying what is in the picture in picture (copy Wallpapers in our image before putting it in the same place)
our image in our eyes will become "transparent" ... :)
on pourra ensuite dessiner dedans en mode Transparent , comme si de rien n’était (ici j’écris un text :) ) mais j'aurai pu dessiner n'importe quoi
bien sur, ici notre image a en fait comme couleur de fond , ce qui se trouve Sous elle :)
we can then draw in Transparent mode
(here I am writing a text :)) but I could draw anything
of course, here in our image as the background color is, what is under it :)
pour cette exemple j’écris un text , mais vous pouvez utiliser ce code pour afficher ce que vous voulez dans ce "cadre" transparent :)
l'image est volontairement affichée a droite, de façon a dépasser le cadre de l’éditeur.. vous verrez ainsi que notre image est Réellement Transparente
puisqu'on apperçois le cadre exterieur de l'editeur qui traverse notre image (bonjour l'arnaque :lol: )
for this example I write a text, but you can use this code to display what you want in this "framework" transparent :)
the image is displayed on the right voluntarily, so has exceed the box editor ..
and you will see that our image is "Really" Transparent
we see the outer frame the editor, that crosses our image (hello scam: lol:)
j'ai mis ça en procédure
I put it in procedure
affiche_image_transparent(num_window,text$,x,y,larg,haut)
num_window = the number of the window that will host our image
text$ =the text we want to write ... (because this procedure is dedicated to it .. but read the contents of the process to understand
x= position X of the image, transparent
y= y position of the image, transparent
larg = width of our image, transparent
haut= height of our image transparent


Code: Select all

; Code By Dobro
Declare  OpenWindow_Window()
Declare  affiche_image_transparent(num_window,text$,x,y,larg,haut)




;{- Enumerations / DataSections
;{ Windows
Enumeration
	#Window
EndEnumeration
;}
;{ Gadgets
Enumeration
	#Editor
	#image
EndEnumeration
;}
;}
Procedure OpenWindow_Window()
	If OpenWindow(#Window, 447, 170, 400, 400, "Test", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
		;If CreateGadgetList(WindowID(#Window))
		
		EditorGadget(#Editor, 17, 28, 364, 352)
		SetGadgetText(#Editor, "ceci est un editeur ")
		
		;EndIf
	EndIf
EndProcedure

OpenWindow_Window()
text$="Coucou"
x=330
y=100
larg=200
haut=40
num_window=#window
affiche_image_transparent(num_window,text$,x,y,larg,haut)
;{- Event loop

Repeat
	
	Select WaitWindowEvent(2)
		; ///////////////////
		Case #PB_Event_Gadget
		Select EventGadget()
			Case #Editor
		EndSelect
		; ////////////////////////
		Case #PB_Event_CloseWindow
		Select EventWindow()
			
			Case #Window
			CloseWindow(#Window)
			Break
		EndSelect
	EndSelect
Forever
;
;}




procedure affiche_image_transparent(num_window,text$,x,y,larg,haut)
	; By Dobro
	; on va creer l'illusion de transparence !!
	; principe : on effectue une copie d'ecran de ce qui se trouve sous l'image
	; on pose cette copie dans l'image , 
	; on ecrit le text en mode transparent dans l'image
	; on affiche le tout
	; on a ainsi l'illusion d'une image transparente
	
	;{ ne pas toucher la dedans
	; ************************************************************************
	source=GetDC_( WindowID (num_window))
	if CreateImage(#image,larg,haut,32)
		Destination = StartDrawing(ImageOutput(#image))
		BitBlt_(Destination,0,0,Larg,Haut,source,x,y,#SRCCOPY)
		ReleaseDC_(WindowID (num_window),Destination)
		ReleaseDC_(WindowID (num_window),source)
		DrawingMode(#PB_2DDrawing_Transparent)
		DrawText(1,1,text$,RGB(0,255,0),RGBA(0,0,0,0))
	StopDrawing()
	Else
	MessageRequester("info","pas pu creer l'image")
	ProcedureReturn
endif
; ***********************************************************************
;}

; ici on dessine dans notre image transparente
; vous pouvez vous servir de cette image comme vous le voulez (ici j'ecrit un text , mais vous pouvez dessiner un rond un carre ...etc ... )
; on l'affiche sur la fenetre
If IsImage(#image)
	StartDrawing(WindowOutput(num_window))
		DrawImage(ImageID( #image),x,y)
	StopDrawing()
endif

delay(5000) ; pendant 5 secondes


;{ ne pas toucher la dedans
; ************************************************************************
; detruit l'image
If IsImage((#image))<>0
	FreeImage(#image)
EndIf
; ************************************************************************
;}
endprocedure
; EPB

ps :nothing prevents you to use DrawAlphaImage () instead of DrawImage , if you want to AlpheBlend effect on what you draw in the image Transparent :)
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: image and Transparency ( to produce a layer with an imag

Post by dobro »

http://www.purebasic.fr/english/viewtop ... 3&t=29893&

thin, I just saw that is made ​​SROD here is almost the same thing :lol:
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
Post Reply