如何转换android颜色格式? [英] How to convert android color format?

查看:141
本文介绍了如何转换android颜色格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个颜色选择器对话框,您可以在其中选择按钮的颜色,文本颜色等.如果我记录选择的颜色,则会得到一个-13459125数字,但我不知道它是什么RGB颜色.我看到它是24位颜色代码,因为可以选择256 * 256 * 256的颜色,但是如何将其转换为可以定义其RGB代码的格式呢?我不确定为什么它也不是负数...

I have a colorpicker dialog, where you can choose colors for a button, textcolor etc. If I log the choosen color, I get a -13459125 number which I dont know what RGB color is. I see that it's a 24-bit color code because 256*256*256 color can be selected, but how can I convert it to a format where I can define its RGB codes? I am not sure why it is negative either...

推荐答案

将4字节压缩为一个整数,作为0xAARRGGBB

Its packed 4-bytes to an integer as 0xAARRGGBB

您的值(-13459125)为0xFF32A14B或

Your value (-13459125), is 0xFF32A14B, or

A = 255 R = 50 G = 161 B = 75(十进制).

A=255 R=50 G=161 B=75 in decimal.

如果颜色为c,则可以使用以下方法获取组件:

If you have a color c, you can get the components with:

int red = Color.red(c)
int green = Color.green(c)

这篇关于如何转换android颜色格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆