Question to Transparence

Just starting out? Need help? Post your questions and find answers here.
Cyllceaux
Enthusiast
Enthusiast
Posts: 514
Joined: Mon Jun 23, 2014 1:18 pm

Question to Transparence

Post by Cyllceaux »

I'm not sure why, but when I use transparence, it only worked in Vector. What am I doing wrong?

Code: Select all

EnableExplicit

Define w=DesktopScaledX(200)
Define h=DesktopScaledY(200)

OpenWindow(0,0,0,640,220,"Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ImageGadget(1,10,10,200,200,0,#PB_Image_Border)
ImageGadget(2,220,10,200,200,0,#PB_Image_Border)
ImageGadget(3,430,10,200,200,0,#PB_Image_Border)

Define timage1=CreateImage(#PB_Any,w,h,32,#PB_Image_Transparent)
StartDrawing(ImageOutput(timage1))
Box(DesktopScaledX(50),DesktopScaledY(50),DesktopScaledX(100),DesktopScaledY(100),#Red)
StopDrawing()

Define timage2=CreateImage(#PB_Any,w,h,32,#PB_Image_Transparent)
StartVectorDrawing(ImageVectorOutput(timage2))
VectorSourceColor(RGBA(255,0,0,255))
AddPathBox(DesktopScaledX(50),DesktopScaledY(50),DesktopScaledX(100),DesktopScaledY(100))
FillPath()
StopDrawing()


Define timage3=CreateImage(#PB_Any,w,h,32)
StartDrawing(ImageOutput(timage3))
Box(DesktopScaledX(50),DesktopScaledY(50),DesktopScaledX(100),DesktopScaledY(100),#Red)
StopDrawing()


Define image1=CreateImage(#PB_Any,w,h,32,#PB_Image_Transparent)
StartDrawing(ImageOutput(image1))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawAlphaImage(ImageID(timage1),0,0)
StopDrawing()

Define image2=CreateImage(#PB_Any,w,h,32,#PB_Image_Transparent)
StartDrawing(ImageOutput(image2))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawAlphaImage(ImageID(timage2),0,0)
StopDrawing()

Define image3=CreateImage(#PB_Any,w,h,32,#PB_Image_Transparent)
StartDrawing(ImageOutput(image3))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawAlphaImage(ImageID(timage3),0,0)
StopDrawing()

SetGadgetState(1,ImageID(image1))
SetGadgetState(2,ImageID(image2))
SetGadgetState(3,ImageID(image3))

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
Only the VectorGraphic is showing a red box. But the 2D don't.

Image
User avatar
Caronte3D
Addict
Addict
Posts: 1371
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Question to Transparence

Post by Caronte3D »

I don't know if that's what you want...

Code: Select all

EnableExplicit

Define w=DesktopScaledX(200)
Define h=DesktopScaledY(200)

OpenWindow(0,0,0,640,220,"Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ImageGadget(1,10,10,200,200,0,#PB_Image_Border)
ImageGadget(2,220,10,200,200,0,#PB_Image_Border)
ImageGadget(3,430,10,200,200,0,#PB_Image_Border)

Define timage1=CreateImage(#PB_Any,w,h,32,#PB_Image_OriginalDepth)
StartDrawing(ImageOutput(timage1))
Box(DesktopScaledX(50),DesktopScaledY(50),DesktopScaledX(100),DesktopScaledY(100),#Red)
StopDrawing()

Define timage2=CreateImage(#PB_Any,w,h,32,#PB_Image_OriginalDepth)
StartVectorDrawing(ImageVectorOutput(timage2))
VectorSourceColor(RGBA(255,0,0,255))
AddPathBox(DesktopScaledX(50),DesktopScaledY(50),DesktopScaledX(100),DesktopScaledY(100))
FillPath()
StopDrawing()


Define timage3=CreateImage(#PB_Any,w,h,32,#PB_Image_OriginalDepth)
StartDrawing(ImageOutput(timage3))
Box(DesktopScaledX(50),DesktopScaledY(50),DesktopScaledX(100),DesktopScaledY(100),#Red)
StopDrawing()


Define image1=CreateImage(#PB_Any,w,h,32,#PB_Image_Transparent)
StartDrawing(ImageOutput(image1))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawAlphaImage(ImageID(timage1),0,0)
StopDrawing()

Define image2=CreateImage(#PB_Any,w,h,32,#PB_Image_Transparent)
StartDrawing(ImageOutput(image2))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawAlphaImage(ImageID(timage2),0,0)
StopDrawing()

Define image3=CreateImage(#PB_Any,w,h,32,#PB_Image_Transparent)
StartDrawing(ImageOutput(image3))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawAlphaImage(ImageID(timage3),0,0)
StopDrawing()

SetGadgetState(1,ImageID(image1))
SetGadgetState(2,ImageID(image2))
SetGadgetState(3,ImageID(image3))

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
Cyllceaux
Enthusiast
Enthusiast
Posts: 514
Joined: Mon Jun 23, 2014 1:18 pm

Re: Question to Transparence

Post by Cyllceaux »

I want a transparent Image in a transparent Image.

With Vector it worked fine.

What does #PB_Image_OriginalDeph? I thought the flags only allowed #PB_Image_Transparent
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Question to Transparence

Post by infratec »

Code: Select all

EnableExplicit

Define w=DesktopScaledX(200)
Define h=DesktopScaledY(200)

OpenWindow(0,0,0,640,220,"Test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ImageGadget(1,10,10,200,200,0,#PB_Image_Border)
ImageGadget(2,220,10,200,200,0,#PB_Image_Border)
ImageGadget(3,430,10,200,200,0,#PB_Image_Border)

Define timage1=CreateImage(#PB_Any,w,h,32,#PB_Image_Transparent)
If StartDrawing(ImageOutput(timage1))
  DrawingMode(#PB_2DDrawing_AllChannels)
  Box(DesktopScaledX(50),DesktopScaledY(50),DesktopScaledX(100),DesktopScaledY(100), RGBA(255, 0, 0, 255))
  StopDrawing()
EndIf

Define timage2=CreateImage(#PB_Any,w,h,32,#PB_Image_Transparent)
If StartVectorDrawing(ImageVectorOutput(timage2))
  VectorSourceColor(RGBA(255,0,0,255))
  AddPathBox(DesktopScaledX(50),DesktopScaledY(50),DesktopScaledX(100),DesktopScaledY(100))
  FillPath()
  StopDrawing()
EndIf


Define timage3=CreateImage(#PB_Any,w,h,32)
If StartDrawing(ImageOutput(timage3))
  DrawingMode(#PB_2DDrawing_AllChannels)
  Box(DesktopScaledX(50),DesktopScaledY(50),DesktopScaledX(100),DesktopScaledY(100), RGBA(255, 0, 0, 255))
  StopDrawing()
EndIf


Define image1=CreateImage(#PB_Any,w,h,32,#PB_Image_Transparent)
If StartDrawing(ImageOutput(image1))
  DrawingMode(#PB_2DDrawing_AlphaBlend)
  DrawAlphaImage(ImageID(timage1),0,0)
  StopDrawing()
EndIf

Define image2=CreateImage(#PB_Any,w,h,32,#PB_Image_Transparent)
If StartDrawing(ImageOutput(image2))
  DrawingMode(#PB_2DDrawing_AlphaBlend)
  DrawAlphaImage(ImageID(timage2),0,0)
  StopDrawing()
EndIf

Define image3=CreateImage(#PB_Any,w,h,32,#PB_Image_Transparent)
If StartDrawing(ImageOutput(image3))
  DrawingMode(#PB_2DDrawing_AlphaBlend)
  DrawAlphaImage(ImageID(timage3),0,0)
  StopDrawing()
EndIf

SetGadgetState(1,ImageID(image1))
SetGadgetState(2,ImageID(image2))
SetGadgetState(3,ImageID(image3))

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
Cyllceaux
Enthusiast
Enthusiast
Posts: 514
Joined: Mon Jun 23, 2014 1:18 pm

Re: Question to Transparence

Post by Cyllceaux »

THX!!!!!

It worked!!!!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Question to Transparence

Post by netmaestro »

Code: Select all

Define Tcolor.l
Declare TransparentCallback(x, y, sourcecolor.l, targetcolor.l)

LoadImage(0, #PB_Compiler_Home + "examples\sources\data\geebee2.bmp")
StartDrawing(ImageOutput(0))
  Tcolor = Point(0,0)
StopDrawing()

CreateImage(1, ImageWidth(0), ImageHeight(0), 32, #PB_Image_Transparent)

StartDrawing(ImageOutput(1))
  DrawingMode(#PB_2DDrawing_CustomFilter)
  CustomFilterCallback(@TransparentCallback())
  DrawImage(ImageID(0),0,0)
StopDrawing()

OpenWindow(0,0,0,ImageWidth(0)*2,ImageHeight(0),"Transparent Drawing Example",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ImageGadget(0,0,0,0,0,ImageID(0))
ImageGadget(1,ImageWidth(0),0,0,0,ImageID(1))
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow

Procedure TransparentCallback(x, y, sourcecolor.l, targetcolor.l) 
  Shared Tcolor
  If Red(sourcecolor) = Red(Tcolor)     And
     Green(sourcecolor) = Green(Tcolor) And
     Blue(sourcecolor) = Blue(Tcolor)
    targetcolor = RGBA(0,0,0,0)
  Else
    targetcolor = sourcecolor
  EndIf
  ProcedureReturn targetcolor  
EndProcedure
BERESHEIT
User avatar
ChrisR
Addict
Addict
Posts: 1484
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Question to Transparence

Post by ChrisR »

Very nice and useful example with the Tcolor and the TransparentCallback, thanks for sharing NM :)
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: Question to Transparence

Post by RASHAD »

NM is the Graphics Master since PB started :)
Search the forum for his layers clock example to see what I mean
Egypt my love
User avatar
skywalk
Addict
Addict
Posts: 4242
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Question to Transparence

Post by skywalk »

On my to do list:
Layers + transparency on canvas gadget.

Mainly to have automatic antialiased text.
But, I stumbled with layers when canvasgadget was added.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Question to Transparence

Post by netmaestro »

The Canvas Gadget itself is not transparent so you couldn't use it to achieve transparency through to the desktop.
BERESHEIT
User avatar
skywalk
Addict
Addict
Posts: 4242
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Question to Transparence

Post by skywalk »

Ouch :(
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply