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

📄 tools.java

📁 自己用java写的rpg小游戏....用到了小图拼大地图技术.
💻 JAVA
字号:
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

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

public class Tools 
{
	public static void paintImage( Graphics g, Image im, int x,int y,int ix,int iy,int w,int h)
	{
		g.setClip( x,y,w,h);
		g.drawImage( im,x-ix,y-iy,0);
		g.setClip( 0,0,500,500);
	}
	
	public static void writeInt ( int n,OutputStream os)
	{
		byte[] d;
		ByteArrayOutputStream  bos =new  ByteArrayOutputStream();
		DataOutputStream  dos=new  DataOutputStream(bos);
		try {
			dos.writeInt( n);
			d=bos.toByteArray() ;
			os.write (d);
			dos.close() ;
			bos.close() ;
		} catch (IOException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
	}
	
	public static int rendInt(InputStream is)
	{
		int s=0;
		
		byte[] d=new byte[4];
		try {
			is.read(d);
			ByteArrayInputStream bis =new ByteArrayInputStream (d);
			DataInputStream dis =new DataInputStream(bis);
			s=dis.readInt() ;
			dis.close() ;
			bis.close() ;
		} catch (IOException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		} 
		return s;
	}
	public static Image[] getImage(String s)
	{
		Image[] im= null;
		byte[] data;
		InputStream  is =" ".getClass() .getResourceAsStream( s);
		int n=Tools.rendInt( is);
		im=new Image[n];
		int [] l=new int [n];
		for(int i=0;i<n;i++)
		{
			l[i]=Tools.rendInt( is);
		}
		for(int i=0;i<n;i++)
		{
			data=new byte[l[i]];
			try {
				is.read(data);
			} catch (IOException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			} 
			im[i]=Image.createImage( data,0,l[i]);
		}
		try {
			is.close() ;
		} catch (IOException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		return im;
	
	}
	
}
















⌨️ 快捷键说明

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