J2ME 渐变色的处理方法
来源:互联网 发布:淘宝旗舰店是什么意思 编辑:程序博客网 时间:2024/05/29 17:31
基于MIDP2.0 CLDC1.0。是我自己一直在用的一个方法,基本机型都是支持的。只要在paint调用即可
Java代码
- private static int[] retrieveRGBComponent(int color) {
- int[] rgb = new int[3];
- rgb[0] = (color & 0x00ff0000) >> 16;
- rgb[1] = (color & 0x0000ff00) >> 8;
- rgb[2] = (color & 0x000000ff);
- return rgb;
- }
- private static int[] generateTransitionalColor(int color1, int color2,
- int steps) {
- int[] color1RGB = retrieveRGBComponent(color1);
- int[] color2RGB = retrieveRGBComponent(color2);
- if (steps < 3 || color1RGB == null || color2RGB == null)
- return null;
- int[] colors = new int[steps];
- colors[0] = color1;
- colors[colors.length - 1] = color2;
- steps = steps - 2;
- int redDiff = color2RGB[0] - color1RGB[0];
- int greenDiff = color2RGB[1] - color1RGB[1];
- int blueDiff = color2RGB[2] - color1RGB[2];
- // from the second to the last second.
- for (int i = 1; i < colors.length - 1; i++) {
- colors[i] = generateFromRGBComponent(new int[] {
- color1RGB[0] + redDiff * i / steps,
- color1RGB[1] + greenDiff * i / steps,
- color1RGB[2] + blueDiff * i / steps });
- }
- return colors;
- }
- private static int generateFromRGBComponent(int[] rgb) {
- if (rgb == null || rgb.length != 3 || rgb[0] < 0 || rgb[0] > 255
- || rgb[1] < 0 || rgb[1] > 255 || rgb[2] < 0 || rgb[2] > 255)
- return 0xfffff;
- return rgb[0] << 16 | rgb[1] << 8 | rgb[2];
- }
- /**
- *
- * @param g
- * @param x
- * 起始X
- * @param y
- * 起始Y
- * @param width
- * 宽度
- * @param height
- * 高度
- * @param TransStart
- * 渐变开始颜色
- * @param TransEnd
- * 渐变结束颜色
- */
- public void drawSelectedBackground(Graphics g, int x, int y, int width,
- int height, int TransStart, int TransEnd) {
- // 这样写是从左到右渐变
- // int[] line = generateTransitionalColor(TextShade, TransEnd, width);
- // Image lineImg = Image.createRGBImage(line, line.length, 1, false);
- // for (int i = 0; i < height; i++) {
- // g.drawImage(lineImg, x, y + i, Graphics.LEFT | Graphics.TOP);
- // }
- // 下面的写法是从上到下渐变
- int[] line = generateTransitionalColor(TransStart, TransEnd, height);
- Image lineImg = Image.createRGBImage(line, 1, line.length, false);
- for (int i = 0; i < width; i++) {
- g.drawImage(lineImg, x + i, y, Graphics.LEFT | Graphics.TOP);
- }
- }
- J2ME 渐变色的处理方法
- 安卓shape渐变色的种类及处理方法
- j2me 颜色渐变与透明处理
- html5 渐变色的方法
- J2me图片缩放与渐变色源码
- 关于j2me透明色图片的处理
- j2me大地图处理方法
- J2ME图象的处理
- j2me的键控处理
- J2ME 颜色渐变
- J2ME 颜色渐变
- j2me绘制渐变颜色
- 转:J2ME 颜色渐变
- J2ME image 图象的处理
- J2ME游戏按键处理方法简述
- J2ME:颜色渐变(转)
- J2ME控制响应按键的算法以及冲突检测的方法和动画的处理
- transition transform body渐变色的填充方法
- filestream streamwriter区别
- 结构设计【待完善】
- 3.2 文件I/O_文件描述符
- cnblogs又挂了
- 喜迎图灵五周年盛大庆典 数千本经典图书免费送
- J2ME 渐变色的处理方法
- android文件系统制作教程(4) —- makefile脚本,制作各种单独的分区文件ramdisk.img,system.img,boot.img
- 5800XM上QQ、飞信死机问题解决方法
- 就业感言:用心做好每个阶段应该做好的事
- 【转】传递参数到线程的n个方法
- Linux 2.6下SPI设备模型--------基于AT91RM9200分析
- 人体的十大最佳时间
- Android:快速修改ramdisk.img脚本
- 舍弃浮躁, 50条重要的C++学习建议