question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Converting RGB value to Integer

See original GitHub issue

The Problem:

I would like to add a more following function in to the app:

  1. Function for converting RGB value to integer. → Show live value on the interface (same like #HEX value) → Able to input the number, and change the color. → Able to pass the current value to another function in my app.

  2. Ability to add a blank custom input field into the interfaces (with editable caption) → This doesn’t need to show any value, I’d like that use can able to type input by themselves.

The Solution:

Converting function is pretty simple as below, but I don’t know how to add it into the app…

// convert three r,g,b integers (each 0-255) to a single decimal integer (something between 0 and ~16m)
function colourToNumber(r, g, b) {
  return (r << 16) + (g << 8) + (b);
}

// convert it back again (to a string)
function numberToColour(number) {
  const r = (number & 0xff0000) >> 16;
  const g = (number & 0x00ff00) >> 8;
  const b = (number & 0x0000ff);
  
  return [r, g, b];
  // or eg. return `rgb(${r},${g},${b})`;
}

Could you help me please? contact: pc@passch.com

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Passchcommented, Nov 10, 2021

Thank you @Wondermarin 😃

0reactions
Wondermarincommented, Nov 10, 2021

Thank you !

But after I set useColor as “rgb” → I can’t select another color anymore. Could you please check what i did wrong?

https://codesandbox.io/s/heuristic-river-f9htb?file=/src/App.js

thanks

This is related with bug #25, which has already been fixed. The update will be released this week.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Convert RGB values to Integer - java - Stack Overflow
// rgbs is an array of integers, every single integer represents the // RGB values combined in some way int r = (int)...
Read more >
RGB Int Calculator - Shodor
This page will let you enter in RGB values, and by pressing evaluate, see the correspinding hexadecimal and integer representations of the color....
Read more >
Convert RGB to Decimal - Color Conversions - CheckYourMath
Online calculator to convert RGB to Decimal color values. Our conversions provide a quick and easy way to convert between Color units.
Read more >
Java Utililty Methods RGB Color Convert To - Java2s.com
Method ; int, RGBtoInt(int r, int g, int b) Converts RGB values to an RGB integer value. return (256 * 256 * r...
Read more >
algorithm to convert integer to 3 variables (rgb)
I try to store integer (real numbers) values into pixel data. The only way my api can store pixel data are RGB Colors....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found