从 ColorPickerDialog.java 检索颜色信息

发布于 2025-01-08 02:02:06 字数 586 浏览 5 评论 0原文

我目前正在使用 Google 提供的 ColorPickerDialog.java。我可以让它正确加载,我可以成功选择一种颜色,按中间的圆圈确认,它会正确存储它的信息。

http://developer.android .com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/ColorPickerDialog.html

由于对话框使用 Canvas 绘制其元素并使用 Paint 类进行着色一切,有没有办法从选择中检索 RGB 浮点值?我不知道这是否简单,我只是想念它,但我还没有完全熟悉Android。

如果它有助于可视化我想要实现的目标,我正在使用 ColorPickerDialog.java 让用户选择一种颜色,并且我想使用该颜色为 OpenGL 中的某些内容着色(所以我需要 float r, float g、浮动 b)

I'm currently using the ColorPickerDialog.java provided by Google. I can get it to load properly, and I can successfully choose a color, press the middle circle to confirm, and it will store it's information properly.

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/ColorPickerDialog.html

Since the dialog uses Canvas to draw its elements and the Paint class to color everything, is there a way to retrieve the RGB float value from the selection? I don't know if it's simple and I'm just missing it, but I'm not fully acquainted with Android yet.

If it helps to visualize what I'm trying to achieve, I'm using the ColorPickerDialog.java to let the user select a color, and I want to use that color to tint some things in OpenGL (so I need float r, float g, float b)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

亽野灬性zι浪 2025-01-15 02:02:06

Color 类可以处理这些转换。返回的整数是按位版本,通常编码为 ARGB,但有一些函数可以将其拆分。

import android.graphics.Color;

public class ColorComponents implements OnColorChangedListener {
    void colorChanged(int color) {
        final int red = Color.red(color);
        final int green = Color.green(color);
        final int blue = Color.blue(color);
    }
}

The Color class can handle these conversions. The integer you are handed back is a bitwise version usually encoded as ARGB but there are functions to split it up.

import android.graphics.Color;

public class ColorComponents implements OnColorChangedListener {
    void colorChanged(int color) {
        final int red = Color.red(color);
        final int green = Color.green(color);
        final int blue = Color.blue(color);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文