how to use the rgb code in the flutter which is given in the figma file - flutter

I have given with the figma File but the color is not matching with the argb in flutter code.
figma file

Just use this function Color.fromRGBO(0, 82, 204, 1).

for using figma rgba color in flutter , you can use Color.fromARGB(int a, int r, int g, int b) .
in your case :
Color.fromARGB(1, 0, 82, 204)

you can use
Color.fromARGB(int opacity, int red, int green, int blue)
with opacity value 1 being not transparent and 0 fully transparent!

Related

How can i convert hex color code to color name or rgb value?

The thing is i have an hex color code which is pass to another screen and when i go to another screen i wanna convert that hex color code to color name or to rgb value is that possible? need some help here.
This is my hex color code value type #ff373334
the package color_models will help you convert a Hex color to CMYK, HSI, HSL, HSP, HSB, LAB, Oklab, RGB, and XYZ.
It's straightforward to use, and if you need a custom implementation, you can check the repository of the package to see how each model work to convert your Hex color to RGB.
Its simple
new Color(0xFF373334)
should work
or
Color(0xFF373334).red
Color(0xFF373334).green
Color(0xFF373334).blue
You can use it like this.
hexStringToColor(String hexColor) {
hexColor = hexColor.toUpperCase().replaceAll("#", "");
if (hexColor.length == 6) {
hexColor = "FF" + hexColor;
}
return Color(int.parse(hexColor, radix: 16));
}
Now you can call this function anywhere like this.
Color color = hexStringToColor(hexString);

How to convert RGB to CIELAB or L* a* b* on Flutter

I have RGB value rgb[253, 216, 28] but i want to convert it to CIELAB or L*,a*,b* value in flutter how can i do it?
You can use package: flutter_color_model. Link: https://pub.dev/packages/flutter_color_models
So we will create a function to convert from RGB to CIELAB for convenient:
List<double> fromRGBtoCIELAB(int red, int green, int blue){
Color color = Color.fromRGBO(red, green, blue, 1);
LabColor labColor = LabColor.fromColor(color);
return [
double.parse(labColor.lightness.toString()),
double.parse(labColor.a.toString()),
double.parse(labColor.b.toString()),
];
}
Remember to add flutter_color_model to your pubspec.yaml file and import 'package:flutter_color_models/flutter_color_models.dart'; in your code ;)

I want to set color of container from [43,43,12] but container takes only color(oxff....)

getColorFromUrl(url).then((color) {
print(color); // [R,G,B] });
I want to make like this Colour(43,43,12), without big brackets
there are other constructors for the Color class
try
Color.fromRGBO(r, g, b, opacity)
and in your case it should be like
Color.fromRGBO(43, 43, 12, 1)
You can make RGB Colors with Color.fromARGB()
You just specify four parameters with R being red, G being green and B being blue. While the a value and that's the alpha value and you set the transparency with it. 0 being transparent and 255 fully opaque.
In your case it would be: Color.fromARGB(0xFF, 0x43, 0x43, 0x12)

sws_scale PAL8 to RGBA returns image that isn't clear

I'm using sws_scale to convert images and videos from every format to RGBA, using an SWSContext created thus:
auto context = sws_getContext(width, height, pix_fmt, width, height, AV_PIX_FMT_RGBA,
SWS_BICUBIC, nullptr, nullptr, nullptr);
but when using a PNG with color type Palette (pix_fmt = AV_PIX_FMT_PAL8) sws_scale doesn't seem to take into account the transparent color, and the resulting RGBA raster isn't transparent. Is this a bug with sws_scale, or am I making some assumption about the result?
palette image:
https://drive.google.com/file/d/1CIPkYeHElNSsH2TAGMmr0kfHxOkYiZTK/view?usp=sharing
RGBA image:
https://drive.google.com/open?id=1GMlC7RxJGLy9lpyKLg2RWfup1nJh-JFc
I was making a wrong assumption - sws_scale doesn't promise to return a premultiplied-alpha color, so the values I was getting were r:255,g:255,b:255,a:0.

Unity is returning material color slightly wrong

I have this mini task in my game where you need to click trophies to change color of the wood on them. I have two arrays of colors, one is an array containing all possible colors and the other one contains four colors (the answer) as follows:
I've double checked that the colors are equal between the two arrays. For example the purple in Colors-array has exactly the same r, g, b & a values as the purple in the Right Order-array.
To check whether the trophies has correct color I just loop through them and grab their material color. Then I check that color against the Right Order-array but it's not quite working. For example when my first trophy is purple it should be correct, but it's not because for some reason Unity is returning slightly different material color than excepted:
Hope somebody knows why this is happening.
When you say, they are exactly same color, I assume you are referring rgb values from Color Inspector, which are not precise values.
Now I dont know what could be causing in different values of colors but
You can write an extension method to compare the values after rounding them to closest integer.
public static class Extensions
{
public static bool CompareRGB(this Color thisColor, Color otherColor)
{
return
Mathf.RoundToInt(thisColor.r * 255) == Mathf.RoundToInt(otherColor.r * 255) &&
Mathf.RoundToInt(thisColor.b * 255) == Mathf.RoundToInt(otherColor.b * 255) &&
Mathf.RoundToInt(thisColor.g * 255) == Mathf.RoundToInt(otherColor.g * 255);
}
}
usage:
Color red = Color.Red;
red.CompareRGB(Color.Red); // true;
red.CompareRGB(Color.Green); // false;
Hope this helps.
I would use a palette. This is simply an array of all the possible colors you use (sounds like you have this). Record, for each "trophy", the INDEX into this array, at the same time you assign the color to the renderer. Also, record the index for each "button", at the same time you assign the color to the renderer.
Then you can simply compare the palette index values (simple integers) to see if the color matches.