随笔博文

Java实现,透明度百分比转换成十六进制

2023-02-06 15:01:09 michael007js 149
下面是Java实现,透明度百分比转换成十六进制: 透明度也是以0到255表示的,所以也是总共有256级,透明是0,不透明是255
for (double i = 1; i >= 0; i -= 0.01) {
 i = Math.round(i * 100) / 100.0d;
 int alpha = (int) Math.round(i * 255);
 String hex = Integer.toHexString(alpha).toUpperCase();
 if (hex.length() == 1) hex = "0" + hex;
 int percent = (int) (i * 100);
 System.out.println(String.format("%d%% — %s", percent, hex))
}


查看效果

首页
关于博主
我的博客
搜索