cancel
Showing results for 
Search instead for 
Did you mean: 

Functions for decoding RGBA colors

Hi,

It would be nice if we could have some way to decode RGBA colors. It would be usefull for example when creating components and we want to separate an input color specified with RGBA function into its red, green, blue and alpha values.

Functions like these would be much appreciated:

  • GetRedValue(<some RGBA color>)
  • GetGreenValue(<some RGBA color>)
  • GetBlueValue(<some RGBA color>)
  • GetAlphaValue(<some RGBA color>)

Or maybe just one function that grabs them all:

  • DecodeRGBA(<some RGBA color>, <variable for red value>, <variable for green value>, <variable for blue value>, <variable for alpha value>)

Emmanuel

Status: New
Comments
Gabrz
Advocate IV

I really like the idea of accessing the R, G, B, A codes of a Color Datatype.

And maybe it could even be possible without extra functions?

 

Say we collect a record like this

Collect(colTest,{col1: Screen1, col2: RGBA(255,0,0,1)})

 

col1 is a Control Datatype (where we can access col1.Name, col1.Fill, etc. of Screen1)

col2 is a Color Datatype. It would be nice if we could access col2.Red, col2.Green, col2.Blue, col2.Alpha.

 

R3dKap
Super User

Hi @Gabrz,

Yeah, sure, that could do the trick as well. It's a good idea... 👍

Imi
Frequent Visitor

Hey Folks,

 

A partial solution though a bit clunky 😉

Set(varColorSample,RGBA(134,2,21,221));
Set(varColorSampleJSON,JSON(varColorSample));

The varColorSampleJSON variable will be #860215ff that you can easily parse.

 

Imperfections 😎:

  • JSON does not support the Alpha value, so that is always FF (255) by my quick tests
  • JSON is a behaviour function so you cannot use it in line, you need "convert" your color variable by and action, OnSelect e.g.

Even if imperfect, might help a bit in certain cases 😉 e.g. when you store the alpha value in separately used config cariables.

 

Have fun

Imi

R3dKap
Super User

Hi @Imi,

I mus admit I never even thought of using the JSON function on a color. But it seems interesting. I'll try that very soon. Thanks for the workaround tip.

@PowerApps team: I'd still love to have a real OOTB solution, whether it is a function or using color "properties" like @Gabrz proposed.

rgsiiiya
Regular Visitor

The ability to get the rbba or hex string out of a Color attribute is actually essential when setting up custom html controls with embedded css.

Example: Creating a nice gradient header (at until we get gradients natively that is 🙂 )

 

That requires css style statement similar to this:
"<div style=""
background: rgb(36,96,164);
background: radial-gradient(circle, rgba(36,96,164,1) 0%, rgba(147,205,203,1) 100%);
width:100%;
height:" & 'Header Gradient Background HTML'.Height - 1 & "px;
"">
</div>"

But, in real app, you would want to replace the rgba() statements with a reference to a Theme's color.  Maybe something like:

 

GetRGBA( myThemeColor.Fill )

or

myThemeColor.Fill.RGBA

 

 

KyllianDL
Frequent Visitor

I would love this. I'm making a component with input colors and need the hex values for building an svg image. 
The only way to get them now is through behavioural functions which is proving to be a pain in the neck. 

It also introduces a lot of unnecessary bloat. 

 

Please make the properties of a colour easily accessible, e.g. color.RGBA, color.hex, color.R, color.G etc.