[Gambas-user] Using gb.Cairo

Tobias Boege tobs at taboege.de
Mon May 17 23:21:03 CEST 2021


On Mon, 17 May 2021, John Dovey wrote:
> I applied another one, slightly different from the first I asked. I figured
> others might like to see:
> 
> Dim hImg As New Image(PictureBox1.W, PictureBox1.H)
>   Dim h As Integer = 60
> 
>   Cairo.Begin(hImg)
>   Cairo.Source = Cairo.SolidPattern(224, 224, 224, 0) ' Background. Pattern
> is RGB
>   Cairo.Paint()
> 
>   Cairo.Font.Name = "Serif"
>   Cairo.Font.Slant = Cairo.FontSlantItalic
>   Cairo.Font.Weight = Cairo.FontWeightBold
>   Cairo.Font.Size = h
> 
>   Cairo.Source = Cairo.SolidPattern(0, 0, 0)
>   Cairo.MoveTo(40, 60)
>   Cairo.Text("El Gato de Fuego")
>   Cairo.Fill
> 
>   Cairo.Source = Cairo.SolidPattern(0.5, 0.5, 0.2)
>   Cairo.MoveTo(43, 63)
>   Cairo.Text("El Gato de Fuego")
>   Cairo.Fill()
> 
>   Cairo.End()
>   PictureBox1.Picture = hImg.Picture
> 
> -- End Code --
> 
> I'm not too sure about the "floating point" parameters. I can't quite
> figure that out. How do I translate for example RGB 102,102,0 (Green) (RGB
> Color Tables <https://www.rapidtables.com/web/color/RGB_Color.html>)  to
> the required floating point? I got the green I wanted from just trial and
> error.

See http://gambaswiki.org/wiki/comp/gb.cairo/cairo/solidpattern:

  The color components are floating point numbers in the range 0 to 1.
  If the values passed in are outside that range, they will be clamped.

RGB color component c between 0 and 255 maps to float f via

  f = c / 255
  c = f * 255

Thus (102, 102, 0) in 256-based RGB notation is (102/255, 102/255, 0/255)
or just (0.4, 0.4, 0.0) in float notation.

Best,
Tobias

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


More information about the User mailing list