PNG格式图片对手机游戏来说有很多不需要的数据,可以通过程序实现,起到压缩和加密png图片的目的!
我搞懂了,有用数据和没用数据,但是不知道如何去除没用数据,并且保留有用数据!
以下的代码。请高人指点,最好给点详细的实例代码!
 public void LoadImage(String strUrl) {
        DataInputStream inputDate = null;
//        ByteArrayInputStream bytearrayInput = null;
        try {
            inputDate = new DataInputStream(new FileInputStream(strUrl));
//            InitByteArray(inputDate.available());   //鍒濆鍖栨暟缁勫ぇ灏?//            inputDate.read(pngByteArray);
//            bytearrayInput=new ByteArrayInputStream(pngByteArray);
            inputDate.skipBytes(64);  //璺宠繃鏂囦欢澶?            m_width = inputDate.readInt();  //瀹藉害
            m_height = inputDate.readInt();  //楂樺害
            m_depth = inputDate.readByte();  //浣嶆繁搴?            inputDate.skipBytes(64);  //璺宠繃IHDR鏂囦欢淇℃伅
            inputDate.skipBytes(4);  //璺宠繃IHDR鏂囦欢CRC淇℃伅
            SkipDate(inputDate, 3);   //璺宠繃3涓暟鎹潡
            SaveDate(inputDate, m_PLTE);  //璺宠繃IHDR鏂囦欢CRC淇℃伅
            SkipDate(inputDate, 6);  //璺宠繃6涓暟鎹潡
            SaveDate(inputDate, m_IDAT);  //璺宠繃IHDR鏂囦欢CRC淇℃伅
            SkipDate(inputDate, 7);  //璺宠繃6涓暟鎹潡
//out.writeInt(0x00000000);   //鏂囦欢灏句俊鎭?//out.writeInt(0x49454e44);
//out.writeInt(0xae426082);
            inputDate.close();
        } catch (FileNotFoundException ex) {
        } catch (IOException ex) {
        }
        System.out.println("------------------------------");
        System.out.println(m_width);
        System.out.println(m_height);
        System.out.println(m_depth);
        System.out.println(m_PLTE);
        System.out.println(m_IDAT);
        System.out.println("------------------------------");
    }    public void SaveImage(String strUrl) {
        DataOutputStream OutputDate = null;
//        ByteArrayInputStream bytearrayInput = null;
        try {
            OutputDate = new DataOutputStream(new FileOutputStream(strUrl));
//            InitByteArray(inputDate.available());   //鍒濆鍖栨暟缁勫ぇ灏?//            inputDate.read(pngByteArray);
//            bytearrayInput=new ByteArrayInputStream(pngByteArray);
            OutputDate.writeInt(m_width);
            OutputDate.writeInt(m_height);
            OutputDate.writeByte(m_depth);
            OutputDate.write(m_PLTE);
            OutputDate.write(m_IDAT);
//out.writeInt(0x00000000);   //鏂囦欢灏句俊鎭?//out.writeInt(0x49454e44);
//out.writeInt(0xae426082);
            OutputDate.close();
        } catch (FileNotFoundException ex) {
        } catch (IOException ex) {
        }
    }//    private void InitByteArray(int available) {
//        pngByteArray = new byte[available];
//    }
    /**淇濆瓨褰撳墠鏁版嵁鍧?*/
    private void SaveDate(DataInputStream inputDate, byte array[]) throws IOException {
        //璺宠繃3涓暟鎹潡
        int tmplength = inputDate.readInt();
        inputDate.skipBytes(1); //璺宠繃IHDR鏂囦欢CRC淇℃伅
        array = new byte[tmplength / 3];
        for (int i = 0; i < array.length; ++i) {
            //cHRM  鍩鸿壊鍜岀櫧鑹茬偣鏁版嵁鍧?            array[i] = inputDate.readByte(); //浣嶆繁搴?        }
        inputDate.skipBytes(1); //璺宠繃IHDR鏂囦欢CRC淇℃伅
    }    private void SkipDate(DataInputStream inputDate, int num) throws IOException {
        //璺宠繃IHDR鏂囦欢CRC淇℃伅
        for (int i = 3; i > 0; --i) {      //cHRM  鍩鸿壊鍜岀櫧鑹茬偣鏁版嵁鍧?            int tmplength1 = inputDate.readInt(); //cHRM淇℃伅length
            inputDate.skipBytes(8 + tmplength1); //璺宠繃IHDR鏂囦欢CRC淇℃伅
        }//out.writeInt(0x00000000);   //鏂囦欢灏句俊鎭?//out.writeInt(0x49454e44);
//out.writeInt(0xae426082);
    }