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

📄 cgloader.java

📁 Java吃豆子游戏
💻 JAVA
字号:
package org.loon.test;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Panel;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;

/**
 * 
 * <p>Title: LoonFramework</p>
 * <p>Description:</p>
 * <p>Copyright: Copyright (c) 2008</p>
 * <p>Company: LoonFramework</p>
 * <p>License: http://www.apache.org/licenses/LICENSE-2.0</p>
 * @author chenpeng  
 * @email:ceponline@yahoo.com.cn 
 * @version 0.1
 */
public class CGloader {
	BufferedImage image;
	int w, h;

	public CGloader(Image org, int w, int h) {
		image = new BufferedImage(w,h,BufferedImage.TYPE_INT_ARGB);
		Graphics offG = image.getGraphics();
		offG.drawImage(org,0,0,null);
		this.w = w;
		this.h = h;
	}
	public CGloader(String filename, Panel panel) {
		ClassLoader cl = getClass().getClassLoader();
		Image org = Toolkit.getDefaultToolkit().createImage(cl.getResource(filename));
		MediaTracker mt = new MediaTracker(panel);
		mt.addImage(org,0);
		try {
			mt.waitForID(0);
		}catch(Exception e) {
			e.printStackTrace();
		}
		w = org.getWidth(panel);
		h = org.getHeight(panel);

		image = new BufferedImage(w,h,BufferedImage.TYPE_INT_ARGB);
		Graphics offG = image.getGraphics();
		offG.drawImage(org,0,0,null);
		offG.dispose();
	}

	public Image getImage() {
		return image;
	}
	public void setAlpha(int x, int y) {
		int oldc = image.getRGB(x,y);
		for(int j=0; j<h; j++) {
		  for(int i=0; i<w; i++) {
		  	if(image.getRGB(i,j)==oldc) {
			  	image.setRGB(i,j,0);
		  	}
		  }
		}
	}
	public BufferedImage crop(int x, int y, int w, int h) {
		return image.getSubimage(x,y,w,h);
	}
}

⌨️ 快捷键说明

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