?? imageset.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;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -