文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Java中颜色的String和Color对象之间的互相转换

Java中颜色的String和Color对象之间的互相转换

时间:2010-05-13  来源:xue2

Java中颜色的String和Color对象之间的互相转换
package org.signsmile;
import java.awt.Color;
public class ColorConverter {
 public static Color String2Color(String str) {
  int i =   Integer.parseInt(str.substring(1),16);  
  return new Color(i);
 }
 public static String Color2String(Color color) {
  String R = Integer.toHexString(color.getRed());
  R = R.length()<2?('0'+R):R;
  String B = Integer.toHexString(color.getBlue());
  B = B.length()<2?('0'+B):B;
  String G = Integer.toHexString(color.getGreen());
  G = G.length()<2?('0'+G):G;
  return '#'+R+B+G;
 }
}
string只是#000000形式的那种 至于blue的那种还没有实现  不过运用反射的话应该可以实现的
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/signsmile/archive/2009/02/17/3899876.aspx
相关阅读 更多 +
排行榜 更多 +
建筑模拟器最新版

建筑模拟器最新版

模拟经营 下载
素人改造师最新版

素人改造师最新版

模拟经营 下载
外星战士幸存者手机版

外星战士幸存者手机版

飞行射击 下载