(or Affinity Photo:))
a demonstration video of this code is available here
https://www.youtube.com/watch?v=n2Wr3FB ... e=youtu.be
basically, we cover the part of the image we want to make disappear.
Pressing the H (horizontal) key will disappear using the left and right of the red zone.
Pressing the V (vertical) key will disappear using what is above and below the red zone
the code :
Code: Select all
;***********************************************
;Titre :*disappear
;Auteur : Zorro (Dobro )
;Date :17/06/2016
;Heure :17:18:16
;Version Purebasic : PureBasic 5.42 LTS (Windows - x86)
;Version de l'editeur :EPB V2.62
; Libairies necessaire : Aucune
;***********************************************
InitMouse()
InitKeyboard()
InitJoystick()
UseJPEGImageDecoder()
UsePNGImageDecoder()
Enumeration
#fenetre
#Police
#curseur
#image
#event_L
#event_H
EndEnumeration
Structure raster
x.l
Y.l
sensx.l
sensy.l
EndStructure
Dim raster.raster(100)
;***********Declaration Procedures *******
Declare disappear(Mode.s,img_num)
; ***********************************
Global Radius=16
Resultat = InitSprite()
FontID = LoadFont(#Police, "arial", 18, #PB_Font_Bold )
file_image$=OpenFileRequester("ouvre une image",GetCurrentDirectory() ,"*.bmp|*.jpg|*.png",1)
If file_image$<>""
LoadImage(#image, file_image$)
Else
End
Endif
ResizeImage(#image,1024,768)
;
WindowID = OpenWindow(#fenetre, 0, 0,1024,768, "Disappear",#PB_Window_SystemMenu|#PB_Window_BorderLess |#PB_Window_ScreenCentered )
Result = OpenWindowedScreen(WindowID(#fenetre) ,0,0, 1027, 768, 1, 0,0)
Repeat
ExamineMouse() :ExamineKeyboard()
WaitWindowEvent(2)
xm=MouseX()
ym=MouseY()
;************ KEYBOARD *****************
If MouseButton(#PB_MouseButton_Left)
; dessin
FLag_mask=#True
StartDrawing( ImageOutput(#Image))
Circle(xm,ym, Radius,RGB(255,13,0))
StopDrawing()
EndIf
if KeyboardPushed(#PB_Key_Escape)
End
Endif
if KeyboardPushed(#PB_Key_H)
Mode.s="H"
Disappear(Mode,#image)
Endif
if KeyboardPushed(#PB_Key_V)
Mode.s="V"
Disappear(Mode,#image)
Endif
if KeyboardPushed(#PB_Key_Add)
Radius=Radius+2
If Radius>300:Radius=300:Endif
Endif
if KeyboardPushed(#PB_Key_Subtract)
Radius=Radius-2
If Radius<1:Radius=1:Endif
Endif
; ****************************************
StartDrawing(ScreenOutput())
DrawImage(ImageID(#Image), 0, 0)
Circle(xm,ym, Radius ,RGB(255,13,0))
StopDrawing()
FlipBuffers():; affiche l'ecran
ClearScreen(RGB(0, 0, 0)) :;efface l'ecran
Until Event=#PB_Event_CloseWindow
;
Procedure Disappear(mode.s,img_num)
;By Zorro (Dobro )
; la procedure Magique !
mem_posy_dep=0
mem_posx_dep=0
mem_posx_arr=0
mem_posy_arr=0
compteur2=0
Haut_im=ImageHeight(img_num)
Larg_im=ImageWidth(img_num)
Select mode
Case "V"
StartDrawing( ImageOutput(img_num))
; ************** Vertical *****************************************************
For x=0 to Larg_im-1
Flag=0:compteur1=0 :compteur2=0:finy=0:starty=0
For y=0 to Haut_im-1
coul=point(x,y)
if coul=rgb(255,13,0)
Starty=y ; retient la position de depart de la zone rouge sur la colone en cours
;calcul la hauteur de la zone mask de la ligne en cours
While coul=rgb(255,13,0)
if Starty+compteur2<Haut_im-1
coul=point(x,Starty+compteur2) ; verifie qu'on est toujours sur le mask
compteur2=compteur2+1 ; << ça va etre notre largeur de travail
Else
Break
Endif
Wend ;<
finy=Starty+compteur2; retient la position de fin de zone rouge pour la ligne en cours !
compteur1=compteur2/2
compteur2=0
if Starty-compteur1>=0 ;
For y1=Starty-compteur1 to Starty
coul=point(x,y1); lit la couleur avant le debut de la zone rouge
Plot(x,y1+compteur1,coul) ; dessine le point en cours avec la nouvelle couleur
Next y1
Endif
For y1=finy to finy+compteur1
If Y1<Haut_im
coul=point(x,y1); lit la couleur apres la zone rouge
Plot(x,y1-compteur1,coul) ; dessine le point en cours avec la nouvelle couleur
Endif
Next y1
Endif
Next y
Next x
StopDrawing()
Case "H"
StartDrawing( ImageOutput(img_num))
; *************************************************************************************
; ************** Horizontal *****************************************************
For y=0 to Haut_im-1
Flag=0:compteur1=0 :compteur2=0:finx=0:startx=0
For x=0 to Larg_im-1
coul=point(x,y)
if coul=rgb(255,13,0)
Startx=x ; retient la position de depart de la zone rouge sur la ligne en cours
;calcul la largeur de la zone mask de la ligne en cours
While coul=rgb(255,13,0)
if Startx+compteur2<Larg_im-1
coul=point(Startx+compteur2,y) ; verifie qu'on est toujours sur le mask
compteur2=compteur2+1 ; << ça va etre notre largeur de travail
Else
Break
Endif
Wend ;<
finx=Startx+compteur2; retient la position de fin de zone rouge pour la ligne en cours !
compteur1=compteur2/2
compteur2=0
if Startx-compteur1>=0 ;
For x1=Startx-compteur1 to Startx
coul=point(x1,y); lit la couleur avant le debut de la zone rouge
Plot(x1+compteur1,y,coul) ; dessine le point en cours avec la nouvelle couleur
Next x1
Endif
For x1=finx to finx+compteur1
If X1 <Larg_im-1
coul=point(x1,y); lit la couleur apres la zone rouge
Plot(x1-compteur1,y,coul) ; dessine le point en cours avec la nouvelle couleur
Endif
Next x1
Endif
Next x
Next y
StopDrawing()
; *************************************************************************************
EndSelect
Endprocedure
; Epb