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

📄 imageset.java

📁 RPG冒险游戏
💻 JAVA
字号:
package CustomlUtil;

import java.io.DataInputStream;
import java.io.InputStream;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Graphics;

public final class ImageSet
{
	public static Image getImageRegion(Image source, 
			int x, int y, int width, int height)
	{
		Image result = Image.createImage(width, height);
		
		if(x + width > source.getWidth() || y + height > source.getHeight())
		{
			System.out.println("Waring: attempting extract using (" + 
					x + "," + y + "," + width + "," + height +") when image is"
					+ "(" + source.getWidth() + "," + source.getHeight() + ")");
		}
		result.getGraphics().drawImage(source, -x, -y, Graphics.TOP | Graphics.LEFT);
		
		return result;
	}
	
	public static Image[] extractFrames(Image source, int sourcex, int sourcey, 
			int framewide, int framehigh, int frameWidth, int frameHeight)
	{
		Image[] frames = new Image[framewide * framehigh];
		
		int frameCount = 0;
		for(int fy = 0; fy < framehigh; fy++)
		{
			for(int fx = 0; fx < framewide; fx++)
			{
				frames[frameCount++] = getImageRegion(source,
						sourcex + (fx * frameWidth), sourcey + (fy * frameHeight),
						frameWidth, frameHeight);
			}
		}
		
		return frames;
	}

	public static Image readImage(String binfile, long pos)
	{
		byte buffer[];
		int len;
		Object o = new Object();
		try
		{
			InputStream is = o.getClass().getResourceAsStream(binfile);
			is.skip(pos);
			
			len = (is.read() & 0xFF) << 24;
			len |= (is.read() & 0xFF) << 16;
			len |= (is.read() & 0xFF) << 8;
			len |= (is.read() & 0xFF);
			
			buffer = new byte[len];
			
			is.read(buffer, 0, buffer.length);
			
			is.close();
			is = null;
			System.gc();
		}
		catch(Exception e)
		{
			buffer = null;
			e.printStackTrace();
			System.gc();
			return null;
		}
		
		return Image.createImage(buffer, 0, buffer.length);
	}
	
	public static byte[] LoadMap(String binfile, int length)
	{
		byte buffer[] = new byte[length];
		Object o = new Object();
	
		try
		{
			InputStream input = o.getClass().getResourceAsStream(binfile);
			DataInputStream dis = new DataInputStream(input);
			
			for(int i = 0; i < length; i++)
			{
					buffer[i]= dis.readByte();
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		
		return buffer;
	}
}

⌨️ 快捷键说明

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