zoukankan      html  css  js  c++  java
  • j2me中生成渐变的颜色条

    /**
    	 * 生成彩色条
    	 * @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;
        }
    
  • 相关阅读:
    洛谷 P2700 逐个击破
    洛谷 P1503 鬼子进村
    洛谷 P1556 幸福的路
    洛谷 P1490 买蛋糕
    洛谷 P2507 [SCOI2008]配对
    code vs 3305 水果姐逛水果街Ⅱ
    通过idea远程调试
    【Cocos2d-x JavaScript Binding】
    ☀【SeaJS】SeaJS Grunt构建
    -_-#【Better Code】throttle / debounce
  • 原文地址:https://www.cnblogs.com/chaohi/p/1945316.html
Copyright © 2011-2022 走看看