Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5542710
  • 博文数量: 763
  • 博客积分: 12108
  • 博客等级: 上将
  • 技术积分: 15717
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-28 21:21
个人简介

业精于勤,荒于嬉

文章分类

全部博文(763)

文章存档

2018年(6)

2017年(15)

2016年(2)

2015年(31)

2014年(14)

2013年(87)

2012年(75)

2011年(94)

2010年(190)

2009年(38)

2008年(183)

2007年(28)

分类: Java

2010-09-13 19:28:12

 
 
游戏数据 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) |
给主人留下些什么吧!~~