help with clearing part of a transparent image

Just starting out? Need help? Post your questions and find answers here.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8433
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

help with clearing part of a transparent image

Post by netmaestro »

Below are two snippets of code. The first is commented out so when you run the program the second snippet runs and shows what I'm trying to accomplish. With #PB_2DDrawing_AllChannels RGBA(0,0,0,0) will clear what's there. However, with Vector drawing there is no #PB_2DDrawing_Allchannels. My question is how to clear part of a transparent image with vector drawing? Is it something that can't be done? Help is appreciated.

Code: Select all

; CreateImage(0,256,256,32,#PB_Image_Transparent)
; StartVectorDrawing(ImageVectorOutput(0))
;   VectorSourceColor(RGBA(0,0,255,255))
;   AddPathCircle(128,128,90)
;   FillPath()
;   VectorSourceColor(RGBA(0,0,0,0))
;   AddPathBox(0,0,128,256) ; <===========  Doesn't do anything
;   FillPath()
; StopVectorDrawing()
; 
; OpenWindow(0,0,0,256,256,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
; ImageGadget(0,0,0,0,0,ImageID(0))
; Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow

CreateImage(0,256,256,32,#PB_Image_Transparent)
StartDrawing(ImageOutput(0))
  DrawingMode(#PB_2DDrawing_AllChannels)
  Circle(128,128,90, RGBA(0,0,255,255))
  Box(0,0,128,256,RGBA(0,0,0,0))
StopDrawing()

OpenWindow(0,0,0,256,256,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ImageGadget(0,0,0,0,0,ImageID(0))
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
BERESHEIT
User avatar
idle
Always Here
Always Here
Posts: 5095
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: help with clearing part of a transparent image

Post by idle »

A little funky though it works!

Code: Select all

CreateImage(0,256,256,32,#PB_Image_Transparent)
StartVectorDrawing(ImageVectorOutput(0))
  VectorSourceColor(RGBA(0,0,255,255))
  AddPathCircle(128,128,90)
  ClipPath()
  AddPathBox(128,0,128,256,#PB_Path_Connected) ; <===========  path connected
  FillPath()
StopVectorDrawing()

OpenWindow(0,0,0,256,256,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ImageGadget(0,0,0,0,0,ImageID(0))
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow

CreateImage(0,256,256,32,#PB_Image_Transparent)
StartDrawing(ImageOutput(0))
  DrawingMode(#PB_2DDrawing_AllChannels)
  Circle(128,128,90, RGBA(0,0,255,255))
  Box(0,0,128,256,RGBA(0,0,0,0))
StopDrawing()

OpenWindow(0,0,0,256,256,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ImageGadget(0,0,0,0,0,ImageID(0))
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
Windows 11, Manjaro, Raspberry Pi OS
Image
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: help with clearing part of a transparent image

Post by #NULL »

I also noticed this. You can't set or replace the alpha channel with a value other than 255, it is always blended, so drawing with alpha 0 does nothing. Depending on what you want to do maybe a combination of vector and 2d drawing blocks helps.

Code: Select all

CreateImage(0,256,256,32,#PB_Image_Transparent)

StartVectorDrawing(ImageVectorOutput(0))
  VectorSourceColor(RGBA(0,0,255,255))
  AddPathCircle(128,128,90)
  FillPath()
StopVectorDrawing()

StartDrawing(ImageOutput(0))
  DrawingMode(#PB_2DDrawing_AllChannels)
  Box(0,0,128,256,RGBA(0,0,0,0))
StopDrawing()

StartVectorDrawing(ImageVectorOutput(0))
  VectorSourceColor(RGBA(0,0,255,255))
  AddPathCircle(128,128,40)
  FillPath()
StopVectorDrawing()

OpenWindow(0,0,0,256,256,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ImageGadget(0,0,0,0,0,ImageID(0))
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: help with clearing part of a transparent image

Post by RASHAD »

Hi NM

#1 :

Code: Select all

CreateImage(1,128,256,32,#PB_Image_Transparent)
StartVectorDrawing(ImageVectorOutput(1))
  VectorSourceColor(RGBA(0,0,255,255))
  AddPathCircle(0,128,90)
  FillPath()
StopVectorDrawing()
  
CreateImage(0,256,256,32,#PB_Image_Transparent)
StartVectorDrawing(ImageVectorOutput(0))
  MovePathCursor(128,0)
  DrawVectorImage(ImageID(1),255)  
StopVectorDrawing()

OpenWindow(0,0,0,256,256,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ImageGadget(0,0,0,0,0,ImageID(0))
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
#2 :

Code: Select all

CreateImage(0,256,256,32,#PB_Image_Transparent)
StartVectorDrawing(ImageVectorOutput(0))
  VectorSourceColor(RGBA(0,0,255,255))
  AddPathCircle(128,128,90)
  FillPath()
  StartDrawing(ImageOutput(0))
    DrawingMode(#PB_2DDrawing_AllChannels)
    Circle(128,128,90, RGBA(0,0,255,255))
    Box(0,0,128,256,RGBA(0,0,0,0))
  StopDrawing()
StopVectorDrawing()

OpenWindow(0,0,0,256,256,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ImageGadget(0,0,0,0,0,ImageID(0))
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
#1 Workaround looks very smooth
Egypt my love
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8433
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: help with clearing part of a transparent image

Post by netmaestro »

Idle: Yep that's funky all right. But it gives the appearance of working because the path is still open when the second draw is done. I need to start with either an image that is done and closed, open it and clear part of it, or when I have it open already, the path is reset (maybe by a fill or stroke without #PB_Path_Preserve) and there is no path, select an area on the output and clear it to transparent. So far I have no joy and I'm going to dream all friggin' night of stupid blue circles grinning back at me as I try in vain to obliterate them.

Rashad, I just saw your post, vetting it now.
BERESHEIT
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8433
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: help with clearing part of a transparent image

Post by netmaestro »

Rashad to the rescue!!

Your #1 doesn't fit the bill because I want to draw a clearing box to the existing circle, not the other way around.

Your #2 is perfect. It works with a closed path, does exactly what I need. I just have trouble believing that a StartDrawing - StopDrawing block actually works inside a vector drawing block. It's one of the ideas I would have eventually got around to trying but I would have given it a 0.001 percent chance of the compiler allowing it. But it's allowed and it's all I'm going to need. Thanks!

PS I hope Fred doesn't see this and say, "What the... I gotta put a stop to this!"
BERESHEIT
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Hilfe beim Löschen eines Teils eines transparenten Bilde

Post by Saki »

Hello everyone
Problems with funky are mostly on Linux
Linux does not like it
地球上の平和
User avatar
idle
Always Here
Always Here
Posts: 5095
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: help with clearing part of a transparent image

Post by idle »

Rashad's #2 didn't work for me on Linux, it just drew a blue circle

seems a odd without logical modes to combine paths, I give up but you can use SaveVectorState() and RestoreVectorState() to undo the clipping.

Code: Select all

CreateImage(0,256,256,32,#PB_Image_Transparent)
StartVectorDrawing(ImageVectorOutput(0))
  VectorSourceColor(RGBA(0,0,255,255))
  AddPathCircle(128,128,90)
  SaveVectorState()
  ClipPath()
  AddPathBox(128,0,128,255,#PB_Path_Connected) ; <===========  path connected
  FillPath()
  RestoreVectorState() 
  AddPathCircle(10,128,5)
  FillPath() 
StopVectorDrawing()

OpenWindow(0,0,0,256,256,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ImageGadget(0,0,0,0,0,ImageID(0))
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow

Windows 11, Manjaro, Raspberry Pi OS
Image
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: help with clearing part of a transparent image

Post by RASHAD »

Hi NM
I kept doing that long time back with previous PB version without any problems :)
Next is a new approach maybe it will suit you too
Happy landing with your Chess project (It is your dream you kept going with it since long time back)
I keep watching your very good work all the time

Code: Select all

CreateImage(0,256,256,32,#PB_Image_Transparent)
StartVectorDrawing(ImageVectorOutput(0))
  VectorSourceColor(RGBA(0,0,255,255))
  AddPathCircle(128,128,90)
  FillPath()
  BeginVectorLayer(255)
    VectorSourceColor($FFF0F0F0)
    AddPathBox(0,0,128,256)
    FillPath()
  EndVectorLayer()
StopVectorDrawing()

OpenWindow(0,0,0,256,256,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ImageGadget(0,0,0,0,0,ImageID(0))
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
I am just pointing to BeginVectorLayer() maybe you can use it do new function
Egypt my love
User avatar
Blue
Addict
Addict
Posts: 886
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: help with clearing part of a transparent image

Post by Blue »

Hi Rashad.
If you have a little time, I'd love to hear some more from you on this subject.
RASHAD wrote:...

Code: Select all

...
  BeginVectorLayer(255)
    VectorSourceColor($FFF0F0F0)
    AddPathBox(0,0,128,256)
    FillPath()
  EndVectorLayer()
...
I don't see what BeginVectorLayer(255) does here ?
If I comment out the 2 xxVectorLayer() lines, I get exactly the same result (Windows 10).
"That's not a bug..." said the programmer. "it's a feature! "
"Oh! I see..." replied the blind man.
Post Reply