如何设置颜色的R,G,B和Alpha分量? [英] How do I set the R, G, B and Alpha components of a color?
本文介绍了如何设置颜色的R,G,B和Alpha分量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有3个整数值构成RGB值,我也有颜色的Alpha分量值。如何设置这4个值以获得所需的颜色
There are 3 integer values that makes up a RGB value, and also i have the Alpha component value of the color. how do i set these 4 values to get the desired colour
推荐答案
您可以创建 颜色
对象(值应该是 0 - 255
或 浮动
s 0f
- 1f
:
You can create a Color
object (the values should either be int
s between 0
-255
or float
s between 0f
-1f
:
Color c = new Color(red, green, blue, alpha);
如果你想用这种颜色绘制图像: / p>
If you want to paint an image with that color:
BufferedImage image = new BufferedImage(300, 200, BufferedImage.TYPE_INT_ARGB);
Graphics graphics = image.getGraphics();
graphics.setColor(c);
graphics.fillRect(50, 50, 100, 100);
graphics.dispose();
如果你只想设置一个像素(颜色模型必须是ARGB):
If you only want to set a pixel (color model must be ARGB):
image.setRGB(50, 50, c.getRGB());
这篇关于如何设置颜色的R,G,B和Alpha分量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文