📄 imageutils.java
字号:
/*
* Created on 2005-8-8
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.swing.game.crystal.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
/**
* @author vampire_a
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class ImageUtils {
public static Logger logger = Logger.getLogger(EquipUtils.class);
static {
PropertyConfigurator.configure("./cfg/Log4j.properties");
}
public static Map initImageMap() {
Map m = new HashMap();
InputStream in = null;
try {
File folder = new File("./icons");
File[] subFolders = folder.listFiles();
for (int i = 0; i < subFolders.length; i++) {
List l = new ArrayList();
m.put(subFolders[i].getName(), l);
File[] files = subFolders[i].listFiles();
String dir = subFolders[i].getPath();
for (int j = 0; j < files.length; j++) {
File f = new File(dir + "/" + j + ".png");
if (f.exists()) {
in = new FileInputStream(f);
int length = 0;
ByteBuffer bb = ByteBuffer.allocate(10000);
byte[] temp = new byte[1000];
int len = 0;
while ((len = in.read(temp, 0, 1000)) != -1) {
bb.put(temp);
length += len;
}
byte[] image = new byte[length];
System.arraycopy(bb.array(), 0, image, 0, length);
l.add(image);
}
}
/*
* for (int j = 0; j < files.length; j++) { if
* (files[j].getName().endsWith("png")) { in = new
* FileInputStream(files[j]); int length = 0; ByteBuffer bb =
* ByteBuffer.allocate(10000); byte[] temp = new byte[1000]; int
* len = 0; while ((len = in.read(temp, 0, 1000)) != -1) {
* bb.put(temp); length += len; } byte[] image = new
* byte[length]; System.arraycopy(bb.array(), 0, image, 0,
* length);
*
* l.add(image); } }
*/
}
} catch (Exception e) {
logger.error(e);
}
return m;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -