gpt4 book ai didi

java - int argb 颜色输出奇怪值

转载 作者:搜寻专家 更新时间:2023-11-01 09:45:50 24 4
gpt4 key购买 nike

我正在尝试创建使用随机颜色的小型应用程序。

Random rnd = new Random();
int color1 = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
int color2 = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
int color3 = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));

但在color1、color2、color3中保存了诸如“-11338194”之类的值。是否可以取argb值? (比如“255255255255”什么的)谢谢!

最佳答案

试试这段代码,

Random rnd = new Random();
int color1 = Color.argb(255, rnd.nextInt(256 - 0), rnd.nextInt(256 - 0), rnd.nextInt(256 - 0));
int color2 = Color.argb(255, rnd.nextInt(256 - 0), rnd.nextInt(256 - 0), rnd.nextInt(256 - 0));
int color3 = Color.argb(255, rnd.nextInt(256 - 0), rnd.nextInt(256 - 0), rnd.nextInt(256 - 0));

Reference for Color.argb()

Generate Random number between range

关于java - int argb 颜色输出奇怪值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38190790/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com