I'm looking for a way to :
- display a selection border (dash-line created from a border shape) from an image (with alpha channel), like I select the alpha channel.
Do you know how I can do that (if possible, no api, to be crossplatform ^^) ?
- a way to get a selection easily thanks to the alpha.
Some images to explain :
- I have this funny cat, (as you can see he's not happy, because he would like to be selected ^^) :

- I select the line. We can see the line+the selection border :

- Or, if I hide the layer, we can see only the selection border (the pixels whith alpha>0)

I have thinking about a technic like remplissage() (=fillarea) by Comtois, see the last post (http://forums.purebasic.com/english/vie ... ght=myfill). But it doesn't take all the pixel non transparent, only the pixels in the selection.
If you an idea on how to achieve that, I will be very happy (better than my cat
In my exemple, I can draw on a selection (made by the two circles), but I would like to see the border of this selection (like in photoshop/gimp).
Code: Select all
; Alpha selection
; by blendman jully 2015
Global w, h
w = 1024
h = 768
Enumeration ; sprite
#Sp_Layer
#Sp_LayerTempo
#Sp_Checker
#Sp_Selection
EndEnumeration
Enumeration ;Image
#Img_Layer
#Img_LayerTempo
#Img_AlphaSel
EndEnumeration
CreateImage(#Img_Layer,w,h,32,#PB_Image_Transparent)
CreateImage(#Img_LayerTempo,w,h,32,#PB_Image_Transparent)
CreateImage(#Img_AlphaSel,w,h,32,#PB_Image_Transparent)
;{ procedure
Procedure cb(x,y,top,bottom)
; by wilbert
If (x!y) & 8; checkerboard pattern
ProcedureReturn top
Else
ProcedureReturn bottom
EndIf
EndProcedure
Procedure Filtre_MaskAlpha(x, y, CouleurSource, CouleurDestination)
ProcedureReturn (CouleurSource & $00FFFFFF) | (Alpha(CouleurSource)*Alpha(CouleurDestination)/255)<<24
EndProcedure
Procedure CanvasUpdate()
If StartDrawing(SpriteOutput(#Sp_Layer))
; Box(0, 0, w, h, RGB(160,160,160))
DrawingMode(#PB_2DDrawing_AlphaChannel)
Box(0,0,w,h,RGBA(0,0,0,0))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawAlphaImage(ImageID(#Img_Layer),0,0)
DrawAlphaImage(ImageID(#Img_AlphaSel),0,0)
; draw the painting
DrawingMode(#PB_2DDrawing_CustomFilter)
CustomFilterCallback(@Filtre_MaskAlpha())
DrawAlphaImage(ImageID(#Img_LayerTempo),0,0)
StopDrawing()
EndIf
ClearScreen(RGB(160,160,160))
DisplayTransparentSprite(#Sp_Checker,0,0)
DisplayTransparentSprite(#Sp_Layer,0,0)
DisplayTransparentSprite(#Sp_Selection,0,0)
FlipBuffers()
EndProcedure
;}
InitSprite()
OpenWindow(0, 0, 0, w, h, "Selection and alpha", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
screenwidth = 1024
screenheight = 768
If OpenWindowedScreen(WindowID(0),0,0,w, h)=0
MessageRequester("Error", "Can't Open Screen!", 0)
End
EndIf
; the image
If StartDrawing(ImageOutput(#Img_Layer))
DrawingMode(#PB_2DDrawing_AlphaChannel)
Box(0,0,w,h,RGBA(0,0,0,0))
StopDrawing()
EndIf
If StartDrawing(ImageOutput(#Img_LayerTempo))
DrawingMode(#PB_2DDrawing_AlphaChannel)
Box(0,0,w,h,RGBA(0,0,0,0))
StopDrawing()
EndIf
If StartDrawing(ImageOutput(#Img_AlphaSel))
DrawingMode(#PB_2DDrawing_AlphaChannel)
; create the mask
Circle(450,350,100,RGBA(0,0,0,255))
Circle(305,240,145,RGBA(0,0,0,120))
StopDrawing()
EndIf
; the sprite (for the preview)
CreateSprite(#Sp_Layer,w,h,#PB_Sprite_AlphaBlending)
CreateSprite(#Sp_LayerTempo,w,h,#PB_Sprite_AlphaBlending)
CreateSprite(#Sp_Selection,w,h,#PB_Sprite_AlphaBlending)
CreateSprite(#Sp_Checker,w,h,#PB_Sprite_AlphaBlending) ; the checker
If StartDrawing(SpriteOutput(#Sp_Checker))
DrawingMode(#PB_2DDrawing_AlphaBlend)
Box(0,0,w,h,RGBA(200,200,200,255))
DrawingMode(#PB_2DDrawing_CustomFilter)
CustomFilterCallback(@cb())
Box(0,0,w,h,RGBA(160,160,160,255))
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#Sp_Selection))
DrawingMode(#PB_2DDrawing_AlphaChannel)
Box(0,0,w,h,RGBA(0,0,0,0))
;DrawingMode(#PB_2DDrawing_Outlined) ; <------------- here, I would like to find a way to see a selection border
; based on the alpha of the shape (the two icrcle, in this exemple),
; which could work With image( it's ok if I use only box(), circle()....
;DrawAlphaImage(ImageID(#Img_AlphaSel),0,0)
StopDrawing()
EndIf
CanvasUpdate()
Repeat
Repeat
Event = WaitWindowEvent(1)
Select Event
Case #PB_Event_CloseWindow
End
Case #WM_LBUTTONDOWN ; left buton down
paint = 1
Case #PB_Event_LeftClick ; left buton up
paint = 0
EndSelect
Until event = 0
If paint = 1
If StartDrawing(ImageOutput(#Img_LayerTempo))
DrawingMode(#PB_2DDrawing_AlphaBlend)
x = WindowMouseX(0)
y = WindowMouseY(0)
Circle(x, y, 50, RGBA(255,120,120,255))
StopDrawing()
EndIf
CanvasUpdate()
EndIf
ForEver


