j2me绘制渐变颜色
2010-08-21 03:01
330 查看
改进了网上一个j2me绘制渐变颜色的方法
/**
* 绘制渐变颜色
* @param gr 画笔
* @param startcolor 起始色值
* @param endcolor 终点色值
* @param direction 渐变方向 0-水平; 1-垂直
* @param x 绘制区域x
* @param y 绘制区域y
* @param w 绘制区域w
* @param h 绘制区域h
*/
public static void drawGradientColor(Graphics gr, int startcolor, int endcolor, int direction, int x, int y, int w, int h) {
int r_start = ((startcolor >>> 16) & 0xFF);
int g_start = ((startcolor >>> 8) & 0xFF);
int b_start = ((startcolor >>> 0) & 0xFF);
int r_end = ((endcolor >>> 16) & 0xFF);
int g_end = ((endcolor >>> 8) & 0xFF);
int b_end = ((endcolor >>> 0) & 0xFF);
int c_r = r_end - r_start;
int c_g = g_end - g_start;
int c_b = b_end - b_start;
if(direction == 0) {
for (int i = 0; i < w; i++) {
int r = r_start + c_r * i / w;
int g = g_start + c_g * i / w;
int b = b_start + c_b * i / w;
gr.setColor(r, g, b);
gr.fillRect(x + i, y, 1, h);
}
} else if(direction == 1) {
for (int i = 0; i < h; i++) {
int r = r_start + c_r * i / h;
int g = g_start + c_g * i / h;
int b = b_start + c_b * i / h;
gr.setColor(r, g, b);
gr.fillRect(x, y + i, w, 1);
}
}
}
/**
* 绘制渐变颜色
* @param gr 画笔
* @param startcolor 起始色值
* @param endcolor 终点色值
* @param direction 渐变方向 0-水平; 1-垂直
* @param x 绘制区域x
* @param y 绘制区域y
* @param w 绘制区域w
* @param h 绘制区域h
*/
public static void drawGradientColor(Graphics gr, int startcolor, int endcolor, int direction, int x, int y, int w, int h) {
int r_start = ((startcolor >>> 16) & 0xFF);
int g_start = ((startcolor >>> 8) & 0xFF);
int b_start = ((startcolor >>> 0) & 0xFF);
int r_end = ((endcolor >>> 16) & 0xFF);
int g_end = ((endcolor >>> 8) & 0xFF);
int b_end = ((endcolor >>> 0) & 0xFF);
int c_r = r_end - r_start;
int c_g = g_end - g_start;
int c_b = b_end - b_start;
if(direction == 0) {
for (int i = 0; i < w; i++) {
int r = r_start + c_r * i / w;
int g = g_start + c_g * i / w;
int b = b_start + c_b * i / w;
gr.setColor(r, g, b);
gr.fillRect(x + i, y, 1, h);
}
} else if(direction == 1) {
for (int i = 0; i < h; i++) {
int r = r_start + c_r * i / h;
int g = g_start + c_g * i / h;
int b = b_start + c_b * i / h;
gr.setColor(r, g, b);
gr.fillRect(x, y + i, w, 1);
}
}
}
相关文章推荐
- 在VC中用GDI+绘制角度可变的颜色渐变效果-.NET教程,VB.Net语言[转]
- j2me中生成渐变的颜色条
- VC 绘制颜色渐变区域
- HTML5绘制颜色渐变
- PHP绘制渐变颜色图片
- 用Qt绘制颜色渐变
- 在VC中用GDI+绘制角度可变的颜色渐变效果
- 绘制颜色渐变三角形
- J2ME:颜色渐变(转)
- android绘图---绘制颜色渐变的圆圈进度条
- 绘制颜色渐变矩形函数
- 使用Bitmap绘制渐变颜色
- 利用CAGradientLayer绘制颜色渐变动画
- J2ME 颜色渐变
- J2ME 颜色渐变
- 在VC中用GDI+绘制角度可变的颜色渐变效果
- 转:J2ME 颜色渐变
- iOS: CGPathRef上绘制渐变颜色
- iOS 动画绘制线条颜色渐变的折线图
- 自动绘制相关图形及实现渐变颜色