j2me中生成渐变的颜色条
2011-01-26 11:45
239 查看
/** * 生成彩色条 * @param startColor * @param endColor * @param w * @param h * @param step * @return */ public static Image createBarImage(int startColor, int endColor, int w, int h, int step) { Image colorBarImage = Image.createImage(w, h); Graphics g = colorBarImage.getGraphics(); drawTransition(g, 0, w, startColor, endColor, step, h, 0, false); return colorBarImage; } /** * 画渐变的bar * @param g * @param y * @param total * @param startColor * @param endColor * @param perStep * @param len * @param x * @param isHor */ public static void drawTransition(Graphics g, int y, int total, int startColor, int endColor, int perStep, int len, int x, boolean isHor) { int paintCount =0; paintCount=(total + perStep - 1) / perStep; for (int i = 0; i < paintCount; i++) { int color = getTransationColor(startColor, endColor, paintCount, i); g.setColor(color); if(isHor) { g.fillRect(x, y, len, perStep); y += perStep; } else { g.fillRect(x, y, perStep, len); x+=perStep; } } } /** * 从开始颜色渐变到结束颜色 * @param startColor * @param endColor * @param totalCount * @param currentCount * @return */ public static int getTransationColor(int startColor, int endColor, int totalCount, int currentCount) { int sR = (startColor & 0xff0000) >> 16; int sG = (startColor & 0x00ff00) >> 8; int sB = (startColor & 0x0000ff) >> 0; int eR = (endColor & 0xff0000) >> 16; int eG = (endColor & 0x00ff00) >> 8; int eB = (endColor & 0x0000ff) >> 0; int tr = sR + (eR - sR) * currentCount / totalCount; int tg = sG + (eG - sG) * currentCount / totalCount; int tb = sB + (eB - sB) * currentCount / totalCount; int color=(tr<<16)+(tg<<8)+tb; return color; }
相关文章推荐
- 利用OpenCV生成关于某点的颜色径向均匀渐变图像
- 想要生成一组三维的颜色渐变数据?
- android自定义button边框,颜色渐变,圆角button快速生成
- J2ME:颜色渐变(转)
- j2me绘制渐变颜色
- j2me 颜色渐变与透明处理
- 转:J2ME 颜色渐变
- php生成文字颜色渐变 高级用法
- J2ME 颜色渐变
- CSS3可视化渐变背景颜色代码生成插件
- 利用OpenCV生成关于某点的颜色径向均匀渐变图像
- 想要生成一组三维的颜色渐变数据?
- Flex中生成颜色渐变值
- J2ME 颜色渐变
- j2me 颜色渐变与图像透明效果
- JS生成渐变颜色
- 禁用ViewPager左右两侧拉到边界的渐变颜色
- Android之绚丽的图片游览效果--有点像W7效果,透明的倒影,层叠的图片,渐变的颜色透明度
- 让立方体颜色渐变
- 导航栏颜色渐变效果