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条)

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错