⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imagetools.java

📁 Java程序的一个游戏小Demo 里面包括了许多工具类 用起来很方便
💻 JAVA
字号:
package tools;
/**
 * 工具类
 * 图像的高级处理
 */

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class ImageTools {
	/**
	 * 图片翻转
	 * @param g
	 * @param img
	 * @param zhenshu
	 * @param hangshu
	 * @param dangqianzhen
	 * @param x
	 * @param y
	 */
	public void g_draweFramexF(Graphics g, Image img,
							int lie,
							int hangshu,
	                        int dangqianzhen, int x, int y) {
		int tk, tg;
		tk = img.getWidth();
		tg = img.getHeight();
		g.drawRegion(img,
		             (dangqianzhen % lie) * (tk / lie),
		             (dangqianzhen / lie) * (tg / hangshu),
		             tk / lie,
		             tg / hangshu,
		             2,
		             x,
		             y,
		             20);
	}
//-----------------------------------------------------------------------------------------
	/**
	 * 创建半透明图片
	 * @param image:源图
	 * @param Alpha:透明度
	 * @return 创建好的半透明图,如果出错就返回null
	 */
	public static Image createAlphaPic(Image image,int Alpha)
	{
		try
		{
			int[] rgb;
			rgb=new int[image.getWidth()*image.getHeight()];
			image.getRGB(rgb,0,image.getWidth(),0,0,image.getWidth(),image.getHeight());
			for(int i=0;i<rgb.length;i++)
				rgb[i]+=(((Alpha+1)<<24)&0xff000000);
			return(Image.createRGBImage(rgb,image.getWidth(),image.getHeight(),true));
		}
		catch(Exception e)
		{
			return null;
		}
	} 
//-------------------------------------------------------------------------------------------
	/**
	 * 2.0半透明绘制
	 * @param g画笔
	 * @param argbColor颜色
	 * @param x坐标
	 * @param y坐标
	 * @param width宽
	 * @param height高
	 */
	public static void drawClarity(Graphics g,int argbColor,int x,int y ,int width,int height){
		int[] argb = new int[width];
		argb[0] = argbColor;
		for (int tempPos = 1, tempLen; tempPos < argb.length; tempPos += tempLen) {
			tempLen = tempPos;
			System.arraycopy(argb, 0, argb, tempPos, tempPos + tempLen > argb.length ? argb.length - tempPos : tempLen);
		}
		try {
			g.drawRGB(argb, 0, 0, x, y, width, height, true);
		} catch (RuntimeException e) {
			for (int i = height; --i >= 0;){
				g.drawRGB(argb, 0, width, x, y + i, width, 1, true);
			}
		}
		//这个是nokia的
		//DirectUtils.getDirectGraphics(g).fillPolygon(
		//						new int[] { x, x, x + width - 1, x + width - 1 }, 0,
		//						new int[] { y, y + height - 1, y + height - 1, y }, 0,
		//						4, argbColor);
	}
//--------------------------------------------------------------------------------
	/** 
    * 绘制渐变色选择条 
    * @param g 
    * @param color 
    * @param x 
    * @param y 
    * @param width 
    * @param height 
    */ 
	public final static void drawRGBRect(Graphics g, int color, int x, int y,int width, int height) { 
		int[] rgb = getRGBColor(color, width); 
		for (int by = y; by < y + height; by += 4) { 
			int nTemp = y + height - (by - y); 
			nTemp = nTemp > 4 ? 4 : nTemp; 
			g.drawRGB(rgb, 0, width, x, by, width, nTemp, true); 
		}         
	} 
	
	/** 
	* 获取颜色渐变RGB数组
	* @param width 
	* @return 
	*/ 
	public final static int[] getRGBColor(int color, int h) { 
		int[] rgb; 
		int RGB_L = h; 
		int nRgbData = RGB_L * 4; 
		rgb = new int[nRgbData]; 
		int alpha = -127; 
		for (int i = 0; i < RGB_L; i++) { 
			alpha = -127 + i; 
			int col = color|(128 - alpha<< 24); 
			rgb[i] = col; 
			rgb[i + RGB_L] = col; 
			rgb[i + RGB_L * 2] = col; 
			rgb[i + RGB_L * 3] = col; 
		} 
		return rgb; 
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -