java Android 颜色选择器 - 更新颜色数组
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1542806/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android color picker - updating color array
提问by zorglub76
I'm trying to create a color picker for Android that looks like a minimalistic version of Gimp's. So, it has a hue slider and a rectangle with saturation/value variants of a color chosen in hue slider.
我正在尝试为 Android 创建一个颜色选择器,它看起来像 Gimp 的简约版本。因此,它有一个色调滑块和一个矩形,其中包含在色调滑块中选择的颜色的饱和度/值变体。
Question: what is the best way to create the rectangle?
问题:创建矩形的最佳方法是什么?
Right now, I'm creating an 200x200 array of pixels, but it takes ~5sec to create and display rectangle with that array. And I need colors in rectangle to change whenever I change the value in hue slider...
现在,我正在创建一个 200x200 的像素阵列,但使用该阵列创建和显示矩形需要大约 5 秒的时间。每当我更改色调滑块中的值时,我都需要更改矩形中的颜色...
Rectangle is bitmap, btw. Can I use color matrices on that and how? Any examples?
矩形是位图,顺便说一句。我可以在上面使用颜色矩阵吗?如何使用?有什么例子吗?
Thanks in advance!
提前致谢!
回答by Randy Sugianto 'Yuku'
You can create the rectangle with saturation/value variants that change according to the selected hue, by drawing the rectangle with LinearGradients.
通过使用 LinearGradients 绘制矩形,您可以创建具有根据所选色调变化的饱和度/值变量的矩形。
You can incorporate the code here: http://code.google.com/p/android-color-picker/into your application. Seems that this is what you want.
您可以将此处的代码合并到您的应用程序中:http: //code.google.com/p/android-color-picker/。似乎这就是你想要的。
回答by kostmo
OpenIntents has a very nice color picker you can use. It can be installed as an independent app and launched with Intents.
OpenIntents 有一个非常好的颜色选择器,您可以使用。它可以作为一个独立的应用程序安装并通过 Intents 启动。
- Code: http://code.google.com/p/openintents/source/browse/#svn/trunk/ColorPicker
- Screenshots/download: http://www.openintents.org/en/colorpicker
- Intent specification: http://www.openintents.org/en/node/670
回答by CommonsWare
One possibility is to pre-create the rectangles on your developer PC for each slider position, embed them as resources, and then swap in the right one when the slider changes. This may make for a portly application, but it will be nice and quick.
一种可能性是在您的开发人员 PC 上为每个滑块位置预先创建矩形,将它们作为资源嵌入,然后在滑块更改时交换正确的矩形。这可能会成为一个笨重的应用程序,但它会很好而且很快。
I have not dealt with the 2D graphics API much, so I don't know if there are other possibilities (e.g., color matrices).
2D图形API我接触的不多,不知道有没有其他的可能性(比如颜色矩阵)。
回答by Kevin Tan
Can this be applied to an image color picker as well?
这也可以应用于图像颜色选择器吗?
Use case:
用例:
- Select a particular pixel on an image.
- The pixel selected generates a color on a rectangle shape.
- Perhaps generating color codes for the pixel selected?
- 选择图像上的特定像素。
- 选定的像素在矩形形状上生成颜色。
- 也许为所选像素生成颜色代码?

