dousuowu4610 2017-03-06 19:06
浏览 221
已采纳

将负色数转换为HEX或RGB

I've never seen color codes like -1, -16777216, -256, etc. So my current problem is this:

We have a third-party software where you can color-code a value as illustrated in the picture below.

software

Now I'm creating a PHP report that displays those values but I also want to display them using the same colors as what is defined in the software. I was able to hunt the values down from the database but I'm confused as the values are in a format or notation that I'm not familiar with.

database

Could you help me convert these values to either HEX or RGB in either Oracle or PHP which is what I'm used to (I will use it for CSS for the report).

EDIT

Looking at the database and the colors in the software I could at least match the numbers like so:

-1 = White

-12582784 = Purple

-65408 = Pink

-16777216 = Black

-256 = Yellow

Additional Edit

So it looks like 16777216 is a perfect cube number. Its cube root is 256 (on RGB each primary color can be represented by a number from 0-255). So far that's the only relationship I can see think of. I still don't know how to convert that to HEX or RGB though.


I've done some research although not really fruitful. But I'll include it so I don't look like I didn't make an attempt - if you're not interested in it then just ignore it:

16777216 - I started by searching the actual code -16777216 but that didn't return anything so I removed the negative sign.

Facts about 16777216 - that page shows some formulas but I didn't see any that converts to HEX or RGB.

  • 写回答

3条回答 默认 最新

  • dongpo5239 2017-03-06 20:19
    关注

    Your colours are indeed RGB values stored in a slightly twisted way. All you have to do is, take the decimal number away from 16777216 and convert to HEX.

    16777216-1 = 16777215 (FFFFFFh = White)

    16777216-12582784 = 4194432 (400080h = Purple)

    16777216-65408 = 16711808 (FF0080h = Pink)

    16777216-16777216 = 0 (000000h = Black)

    16777216-256 = 16776960 (FFFF00h = Yellow)

    I hope this helps. Apologies for not writing a code, but I am afraid I am not quite there yet in my studies. I promise I will work on it when I get there. :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常