从品牌网站建设到网络营销策划,从策略到执行的一站式服务
1.原理
主要是调用了toHexString(将int类型转为16进制字符串)、parseInt(将字符串解析为int)这两个方法。
2.代码
public static void main(String[] args) { String hexString = colorToHexValue(Color.RED); System.out.println("16进制字符串:" + hexString); Color color = fromStrToARGB(hexString); System.out.println("16进制字符串转为颜色的ARGB值:("+String.valueOf(color.getAlpha())+","+String.valueOf(color.getRed())+"," +String.valueOf(color.getGreen())+","+String.valueOf(color.getBlue())+")"); } private static String colorToHexValue(Color color) { return intToHexValue(color.getAlpha()) + intToHexValue(color.getRed()) + intToHexValue(color.getGreen()) + intToHexValue(color.getBlue()); } private static String intToHexValue(int number) { String result = Integer.toHexString(number & 0xff); while (result.length() < 2) { result = "0" + result; } return result.toUpperCase(); } private static Color fromStrToARGB(String str) { String str1 = str.substring(0, 2); String str2 = str.substring(2, 4); String str3 = str.substring(4, 6); String str4 = str.substring(6, 8); int alpha = Integer.parseInt(str1, 16); int red = Integer.parseInt(str2, 16); int green = Integer.parseInt(str3, 16); int blue = Integer.parseInt(str4, 16); Color color = new Color(red, green, blue, alpha); return color; }
咨询相关问题或预约面谈,可以通过以下方式与我们联系
成都网站建设公司地址:成都市青羊区太升南路288号锦天国际A座10层 建设咨询400-028-6601
成都快上网科技有限公司-四川网站建设设计公司 | 蜀ICP备19037934号 Copyright 2020,ALL Rights Reserved cdkjz.cn | 成都网站建设 | © Copyright 2020版权所有.
专家团队为您提供成都网站建设,成都网站设计,成都品牌网站设计,成都营销型网站制作等服务,成都建网站就找快上网! | 成都网站建设哪家好? | 网站建设地图