Exemplo n.º 1
0
        //============================================================
        // <T>导出多个打包到目录。</T>
        //
        // @param fileName 文件名称
        // @param widthCount 横向分割个数
        // @param hightCount 纵向分割个数
        //============================================================
        public void ExportPath(string path, int tileWidth, int tileHight, int colorCount, int widthCount, int hightCount)
        {
            // 计算分割数量
            int tileCx = _bitmap.Width / tileWidth;
            int tileCy = _bitmap.Height / tileHight;

            // 分割图片
            for (int y = 0; y < tileCy; y++)
            {
                for (int x = 0; x < tileCx; x++)
                {
                    // 绘制局部图形
                    FBitmap bitmap = new FBitmap(tileWidth, tileHight);
                    bitmap.Fill(_bitmap, tileWidth * x, tileHight * y);
                    // 存储索引图片
                    string fileName = path + "_" + RString.PadLeft(y.ToString(), 2, '0') + "_" + RString.PadLeft(x.ToString(), 2, '0') + "." + EXTEND_NAME;
                    _logger.Debug(this, "ExportPath", "Export path file. (file_name={0}, color_count={1}, width_count={2}, hight_count={3})",
                                  fileName, colorCount, widthCount, hightCount);

                    FLzmaFile file = new FLzmaFile();
                    file.EnsureSize(tileWidth * tileHight);
                    StoreCompress(file, bitmap.Native, colorCount, widthCount, hightCount);
                    file.Compress(fileName);
                    file.Reset();
                }
            }
        }
Exemplo n.º 2
0
        //============================================================
        // <T>导出打包文件。</T>
        //
        // @param fileName 文件名称
        // @param widthCount 横向分割个数
        // @param hightCount 纵向分割个数
        //============================================================
        public void ExportFile(string fileName, int colorCount, int widthCount, int hightCount)
        {
            _logger.Debug(this, "ExportFile", "Export file. (file_name={0}, color_count={1}, width_count={2}, hight_count={3})",
                          fileName, colorCount, widthCount, hightCount);
            // 创建压缩文件
            FLzmaFile file = new FLzmaFile();

            file.EnsureSize(_bitmap.Width * _bitmap.Height);
            StoreCompress(file, _bitmap, colorCount, widthCount, hightCount);
            file.Compress(fileName);
        }
Exemplo n.º 3
0
        //============================================================
        // <T>压缩字节数据。</T>
        //
        // @return 字节数据
        //============================================================
        public byte[] CompressBytes()
        {
            byte[] data = null;
            // Deflate压缩
            string compressCd = _compressCd;

            switch (compressCd)
            {
            case ERsCompress.Deflate:
                using (FCompressFile file = new FCompressFile()) {
                    file.Append(_memory, 0, _length);
                    if (_blockSize > 0)
                    {
                        data = file.BlockCompress(_blockSize);
                    }
                    else
                    {
                        data = file.Compress();
                    }
                }
                break;

            case ERsCompress.Lzma:
                using (FLzmaFile file = new FLzmaFile()) {
                    file.Append(_memory, 0, _length);
                    if (_blockSize > 0)
                    {
                        data = file.BlockCompress(_blockSize);
                    }
                    else
                    {
                        data = file.Compress();
                    }
                }
                break;

            case ERsCompress.LzmaAlchemy:
                using (FLzmaFile file = new FLzmaFile()) {
                    file.Append(_memory, 0, _length);
                    if (_blockSize > 0)
                    {
                        data = file.BlockCompressNative(_blockSize);
                    }
                    else
                    {
                        data = file.CompressNative();
                    }
                }
                break;
            }
            // 检查大小,如果压缩后更大,则不压缩数据
            if (data.Length > _length)
            {
                data       = ToArray();
                compressCd = ERsCompress.None;
            }
            // 计算效验码
            _vertifyCode = RByte.ComputeHash32(data, 0, data.Length);
            // 写入文件
            byte[] result = null;
            using (FByteStream stream = new FByteStream()) {
                // 写入信息
                stream.WriteUint8((byte)ERsCompress.Parse(compressCd));
                stream.WriteInt32(_length);
                stream.WriteInt32(_vertifyCode);
                stream.WriteInt32(_blockSize);
                // 写入数据
                if ((ERsCompress.None != compressCd) && (_blockSize > 0))
                {
                    stream.WriteBytes(data, 0, data.Length);
                }
                else
                {
                    stream.WriteInt32(1);
                    stream.WriteInt32(data.Length);
                    stream.WriteBytes(data, 0, data.Length);
                }
                result = stream.ToArray();
            }
            return(result);
        }