[Ok]CreateImage : Does BackColor arg care about alpha?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

[Ok]CreateImage : Does BackColor arg care about alpha?

Post by Olliv »

Hello,

it seems that :

Code: Select all

CreateImage(0, 16, 16, 32, RGBA(0, 0, 0, alphavalue) )
ignores alpha value on PB 5.50 LTS x64.
Last edited by Olliv on Sun Jun 25, 2017 2:43 pm, edited 1 time in total.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8433
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: CreateImage : Does BackColor arg care about alpha channe

Post by netmaestro »

RGB() is the only documented source for the backcolor parameter. You can use an RGBA() colorref without error but as you discovered, also without effect. Your only option would be to create the image with background colorref = #PB_Image_Transparent and then box the RGBA colorref to it with DrawingMode = #PB_2DDrawing_AllChannels.
BERESHEIT
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: CreateImage : Does BackColor arg care about alpha channe

Post by Olliv »

I thank you for telling this option, I tried to replace, but not again for this time.

(to illustrate your help)

Code: Select all

Image = CreateImage(#PB_Any, 16, 16, 32)

If StartDrawing(ImageOutput(Image) )
   ; Reset alpha channel for every pixel
   DrawingMode(#PB_2DDrawing_AllChannels)
   W = OutputWidth()
   H = OutputHeight()
   Box(0, 0, W, H, RGBA(0, 0, 0, 0) )

   ; pattern drawing, especially vector drawing

   StopDrawing()
EndIf
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: CreateImage : Does BackColor arg care about alpha channe

Post by Olliv »

(I replaced 'obviously' by 'especially' and apologize for my mistakes in the language of Shakespeare)
User avatar
chi
Addict
Addict
Posts: 1034
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: CreateImage : Does BackColor arg care about alpha channe

Post by chi »

You forgot #PB_Image_Transparent...

Code: Select all

Image1 = CreateImage(#PB_Any, 64, 64, 32, #PB_Image_Transparent)
If StartDrawing(ImageOutput(Image1))
  DrawingMode(#PB_2DDrawing_AllChannels)
  Box(0, 0, OutputWidth()/2, OutputHeight()/2, RGBA(255, 0, 0, 255))
  Box(OutputWidth()/2, OutputHeight()/2, OutputWidth(), OutputHeight(), RGBA(0, 0, 0, 50))
  StopDrawing()
EndIf

Image2 = CreateImage(#PB_Any, 64, 64, 32, #PB_Image_Transparent)
If StartDrawing(ImageOutput(Image2))
  DrawingMode(#PB_2DDrawing_AlphaBlend)
  Box(0, 0, OutputWidth()/2, OutputHeight()/2, RGBA(255, 0, 0, 255))
  Box(0, 0, OutputWidth(), OutputHeight(), RGBA(0, 0, 0, 50))
  StopDrawing()
EndIf

ShowLibraryViewer("Image", Image1)
CallDebugger
Et cetera is my worst enemy
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: CreateImage : Does BackColor arg care about alpha channe

Post by Olliv »

chi wrote:You forgot #PB_Image_Transparent..
It's not me... I forget nothing ! My brain maybe...
Thank you !

@NetMaestro

Thanks to chi, now I understand fully your help.

Code: Select all

Image = CreateImage(#PB_Any, 16, 16, 32, #PB_Image_Transparent) ; full alpha reset is here now
If StartDrawing(ImageOutput(Image) )

    ; pattern drawing, especially vector drawing

    StopDrawing()
EndIf
Post Reply