游戏数据 resimg.png 中导出 png
private String strImg = "/resimg.png";
// 导出的图片存放在 KEmulator\file 下面
public void test() { int nc = 0; try { InputStream inData = getClass().getResourceAsStream(strImg); DataInputStream in = new DataInputStream(inData); in.skipBytes(nResPos[3][0]); // 读入数据
// short nSize=in.readShort();
for (int i = 0; i < nImgCount.length; i++) { // if (nImgCount[i] > 0 && drawImg[i] == null) {
int nb = in.readShort(); if (nb < 0) { nb+=1<<16; } byte[] data = new byte[nb]; in.read(data); aa(i,data); // drawImg[i] = Image.createImage(data, 0, nb);
// nc++;
// } else if (i + 1 < nImgCount.length)
// in.skipBytes(nResPos[3][i + 1] - nResPos[3][i]);
} in.close(); } catch (Exception e) {
} }
public void aa(int i, byte [] b) { String strFileName = "file:///" + i + ".png"; FileConnection fConn = null; OutputStream out = null; try { fConn = (FileConnection)Connector.open(strFileName,Connector.READ_WRITE); if(!fConn.exists()){ fConn.create(); } out = fConn.openOutputStream(); out.write(b); out.flush(); out.close(); } catch (Exception e) { System.out.println(e.toString()); } }
|
数据的读取部分如下:
try { InputStream inData = getClass().getResourceAsStream(strImg); DataInputStream in = new DataInputStream(inData); in.skipBytes(nResPos[3][0]); //读入数据
//short nSize=in.readShort();
for (int i = 0; i < nImgCount.length; i++) { //int nSkip=i+1 if (nImgCount[i] > 0 && drawImg[i] == null) { short nb = in.readShort(); byte[] data = new byte[nb]; in.read(data); drawImg[i] = Image.createImage(data, 0, nb);
// switch(i){
// case 156:
// case 176:
// case 179:
// case 180:
// case 178:
// drawImg[i]=Fin_LightArray(drawImg[i],80);
// break;
// case 157:
// case 171:
// case 175:
// drawImg[i]=Fin_LightArray(drawImg[i],160);
// break;
// }
nc++; //计算载入进度条
if (nStatus >= STStart && bDrawLoad) { // if(!initLoading)
// {
// nOldStatus = nStatus;
// nStatus = STLoading;
// initLoading = true;
// }
nLoadPecent = (byte) ((100 - nSavePecent) + nSavePecent * nc / nCount); update(); } } else if (i + 1 < nImgCount.length) in.skipBytes(nResPos[3][i + 1] - nResPos[3][i]); } //清除载入进度条
if (nLoadPecent >= 0 && bDrawLoad && !BIsLoading) { nLoadPecent = -1; // nStatus = nOldStatus;
// initLoading = false;
// update();
} nLoadPecent = -1; in.close(); } catch (Exception e) {
}
|
阅读(2161) | 评论(0) | 转发(0) |