Page 1 of 1
Vector drawing clear image to transparent
Posted: Mon Sep 05, 2022 9:27 am
by collectordave
Is it possible to clear an image to transparent using the vector drawing commands?
I start with a transparent image add a box then try to clear the image but the box remains.
the code I am using:
Code: Select all
StartVectorDrawing(ImageVectorOutput(DrawImg))
VectorSourceColor(RGBA(255,255,255,0))
FillVectorOutput()
AddPathBox(0,50,50,50)
VectorSourceColor(#DrawOpaque|#DarkGray)
FillPath()
StopVectorDrawing()
If I set the Alpha channel to 255 it works correctly but is of Course white
A little more digging and found that Vector drawing always blends but found this:
Code: Select all
StartDrawing(ImageOutput(DrawImg))
DrawingMode(#PB_2DDrawing_AlphaChannel )
Box(0, 0, 200, 200, RGBA(0,0,0,0))
StopDrawing()
Using this 2d drawing inside the vector drawing loop works fine.
Re: Vector drawing clear image to transparent
Posted: Mon Jul 01, 2024 12:49 pm
by Michael Vogel
Very annoying that it's needed to do another Start/StopDrawing since CreateImageGadget doesn't allow to set a transparent color as well.
-> would be fine to have an additional parameter for FillVectorOutput() to switch between All_Channel and Blend
Not so easy to get rid of the black border here (except using another Start/StopDrawing)...
Code: Select all
#BrushSize= 29
#BrushCenter= #BrushSize/2
#Zoom= 10*#BrushSize
#DrawOpaque= $ff000000
#ImgPat= 0
OpenWindow(0,0,0,#Zoom,#Zoom,"")
CreateImage(#ImgPat,#BrushSize,#BrushSize,32,#PB_Image_Transparent)
StartVectorDrawing(ImageVectorOutput(#ImgPat))
VectorSourceColor(#White)
;VectorSourceColor($80000000|#Red)
FillVectorOutput()
#C1= #White
#C2= $800000
d.d=50
f.d=100/d
d=f/2
VectorSourceCircularGradient(#BrushCenter-f*3,#BrushCenter-f*3,1+5*d)
VectorSourceGradientColor(#DrawOpaque|#C1, 0.0)
VectorSourceGradientColor(#DrawOpaque|#C1, 0.9)
VectorSourceGradientColor(#C1, 1.0)
AddPathCircle(#BrushCenter-f*3,#BrushCenter-f*3,1+5*d)
FillPath()
AddPathCircle(#BrushCenter+f*3,#BrushCenter+f*3,1+5*d)
VectorSourceColor(#DrawOpaque|#C1)
FillPath()
StopVectorDrawing()
;ShowLibraryViewer("image",#ImgPat)
SetWindowColor(0,$f0e080)
ResizeImage(#ImgPat,#Zoom,#Zoom,#PB_Image_Raw)
ImageGadget(0,0,0,#Zoom,#Zoom,ImageID(#ImgPat))
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
Re: Vector drawing clear image to transparent
Posted: Mon Jul 01, 2024 2:54 pm
by RASHAD
Use the next for speed
Code: Select all
StartDrawing(ImageOutput(DrawImg))
FillMemory(DrawingBuffer(), DrawingBufferPitch() * OutputHeight(),RGBA(0,0,0,0) )
StopDrawing()
Re: Vector drawing clear image to transparent
Posted: Mon Jul 01, 2024 5:00 pm
by Michael Vogel
Does work here (but only with the parameter #PB_Long), anyhow the additional Start/StopDrawing does need some time. Actually I am working with Case 0 of the source code below...
Code: Select all
#BrushSize= 29
#BrushCenter= #BrushSize/2
#Zoom= 10*#BrushSize
#DrawOpaque= $ff000000
#ImgPat= 0
OpenWindow(0,0,0,#Zoom,#Zoom,"")
CreateImage(#ImgPat,#BrushSize,#BrushSize,32,#PB_Image_Transparent)
Select 3
Case 0
bitmap.Bitmap
GetObject_(ImageID(#ImgPat),SizeOf(BITMAP),@bitmap)
FillMemory(bitmap\bmBits,bitmap\bmWidthBytes * bitmap\bmHeight,#White)
Debug PeekL(bitmap\bmBits)
Case 1
StartDrawing(ImageOutput(#ImgPat))
z=DrawingBuffer()
y=DrawingBufferPitch() * OutputHeight()
FillMemory(z,y,#White)
FillMemory(z,y,#Red)
StopDrawing()
Debug PeekL(z)
Case 2
StartDrawing(ImageOutput(#ImgPat))
z=DrawingBuffer()
y=DrawingBufferPitch() * OutputHeight()
StopDrawing()
FillMemory(z,y,#White)
FillMemory(z,y,#Red)
Debug PeekL(z)
Case 3
StartDrawing(ImageOutput(#ImgPat))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0,0,#BrushSize,#BrushSize,#White)
Debug PeekL(DrawingBuffer())
StopDrawing()
EndSelect
StartVectorDrawing(ImageVectorOutput(#ImgPat))
If 0
VectorSourceColor($80000000|#Red)
FillVectorOutput()
EndIf
;VectorSourceColor(#White)
;FillVectorOutput()
#C1= #White
#C2= $800000
d.d=50
f.d=100/d
d=f/2
VectorSourceCircularGradient(#BrushCenter-f*3,#BrushCenter-f*3,1+5*d)
VectorSourceGradientColor(#DrawOpaque|#C1, 0.0)
VectorSourceGradientColor(#DrawOpaque|#C1, 0.9)
VectorSourceGradientColor(#C1, 1.0)
AddPathCircle(#BrushCenter-f*3,#BrushCenter-f*3,1+5*d)
FillPath()
AddPathCircle(#BrushCenter+f*3,#BrushCenter+f*3,1+5*d)
VectorSourceColor(#DrawOpaque|#C1)
FillPath()
StopVectorDrawing()
;ShowLibraryViewer("image",#ImgPat)
SetWindowColor(0,$f0e080)
ResizeImage(#ImgPat,#Zoom,#Zoom,#PB_Image_Raw)
ImageGadget(0,0,0,#Zoom,#Zoom,ImageID(#ImgPat))
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
Re: Vector drawing clear image to transparent
Posted: Mon Jul 01, 2024 9:18 pm
by netmaestro
Nothing to it. Just recreate the image as transparent:
Code: Select all
Declare ButtonHandler_1()
CreateImage(0,320,240,32,#PB_Image_Transparent)
StartVectorDrawing(ImageVectorOutput(0))
VectorSourceColor(RGBA(0,0,255,255))
FillVectorOutput()
StopVectorDrawing()
OpenWindow(0,0,0,320,270,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ImageGadget(0,0,0,0,0,ImageID(0))
ButtonGadget(1,130,245,60,20,"Clear")
BindGadgetEvent(1, @ButtonHandler_1())
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
Procedure ButtonHandler_1()
CreateImage(0,320,240,32,#PB_Image_Transparent)
SetGadgetState(0,ImageID(0))
EndProcedure
Re: Vector drawing clear image to transparent
Posted: Mon Jul 01, 2024 10:08 pm
by Michael Vogel
Can't check it now, but I am quite sure your code will lead to the same result as shiwn above.
Try it with my example and you'll see the problem (dark pixels at the border of the circles).
The reason for this result is the restriction that transparent images are created with black colored pixels and a bug (?) calculation wrong antialiized pixels when drawing vector circles.