J2ME:颜色渐变(转)

1

 1:  import javax.microedition.lcdui.Graphics;
 2:   
 3:  public class CrystalRGB {
 4:   
 5:      public final static void drawRGBVRect(Graphics g, int color, int x, int y,
 6:              int width, int height) {
 7:          int[] rgb = getRGBVColor(color, height);
 8:          for (int i = 0; i < width; i += 4) {
 9:              int nTemp = x + width - (i - x);
10:              nTemp = nTemp > 4 ? 4 : nTemp;
11:              g.drawRGB(rgb, 0, 4, i, y, nTemp, height, true);
12:          }
13:      }
14:   
15:      public final static int[] getRGBVColor(int color, int h) {
16:          int[] rgb;
17:          int RGB_L = h;
18:          int nRgbData = RGB_L * 4;
19:          int a;
20:          rgb = new int[nRgbData];
21:   
22:          for (int i = 0; i < RGB_L; i++) {
23:              a = i;
24:              if (a > 255) {
25:                  a = 255;
26:              }
27:              int col = color | (a << 24);
28:              rgb[i * 4] = col;
29:              rgb[i * 4 + 1] = col;
30:              rgb[i * 4 + 2] = col;
31:              rgb[i * 4 + 3] = col;
32:          }
33:          return rgb;
34:      }
35:   
36:      public final static void drawRGBSRect(Graphics g, int color, int x, int y,
37:              int width, int height) {
38:          int[] rgb = getRGBSColor(color, width);
39:          for (int by = y; by < y + height; by += 4) {
40:   
41:              int nTemp = y + height - (by - y);
42:   
43:              nTemp = nTemp > 4 ? 4 : nTemp;
44:              g.drawRGB(rgb, 0, width, x, by, width, nTemp, true);
45:          }
46:   
47:      }
48:   
49:      public final static int[] getRGBSColor(int color, int h) {
50:          int[] rgb;
51:          int RGB_L = h;
52:          int nRgbData = RGB_L * 4;
53:          rgb = new int[nRgbData];
54:          int alpha = -127;
55:          for (int i = 0; i < RGB_L; i++) {
56:              alpha = -127 + i;
57:              int col = color | (128 - alpha << 24);
58:              rgb[i] = col;
59:              rgb[i + RGB_L] = col;
60:              rgb[i + RGB_L * 2] = col;
61:              rgb[i + RGB_L * 3] = col;
62:          }
63:          return rgb;
64:      }
65:   
66:  }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值