示例#1
0
        //============================================================
        // <T>序列化数据内容到输出流中。</T>
        //
        // @param output 输出流
        //============================================================
        public override void Serialize(IOutput output)
        {
            base.Serialize(output);
            // 写入宽度和高度
            int width  = _bitmap.Width;
            int height = _bitmap.Height;

            output.WriteInt16((short)width);
            output.WriteInt16((short)height);
            // 检测是否有Aplah值
            bool channelA = RBitmap.HasChannel(_bitmap, EBitmapChannel.A);

            if (channelA)
            {
                output.WriteInt8(2);
            }
            else
            {
                output.WriteInt8(1);
            }
            // 保存图片信息
            byte[] data       = RBitmap.ToBytes(_bitmap);
            byte[] dataResult = new byte[data.Length * 2];
            int    length     = RCompressJpg.Compress(dataResult, 0, dataResult.Length, data, 0, data.Length, _bitmap.Width, _bitmap.Height, _qualityColor, 1);

            output.WriteInt32(length);
            output.WriteBytes(dataResult, 0, length);
            // 保存图片A信息
            if (channelA)
            {
                length = RCompressJpg.Compress(dataResult, 0, dataResult.Length, data, 0, data.Length, _bitmap.Width, _bitmap.Height, _qualityAlpha, 2);
                output.WriteInt32(length);
                output.WriteBytes(dataResult, 0, length);
            }
        }
示例#2
0
        //============================================================
        // <T>序列化数据内容到输出流中。</T>
        //
        // @param output 输出流
        //============================================================
        public void SerializeBitmap(IOutput output)
        {
            // 处理位图
            Bitmap bitmap = _bitmap;

            if ((_validLocation.X != 0) || (_validLocation.Y != 0) || (_validSize.Width != _bitmap.Width) || ((_validSize.Height != _bitmap.Height)))
            {
                bitmap = new Bitmap(_validSize.Width, _validSize.Height, PixelFormat.Format32bppArgb);
                // 复制图片
                RBitmap.Copy(_bitmap, new SIntRectangle(_validLocation.X, _validLocation.Y, _validSize.Width, _validSize.Height), bitmap, new SIntPoint2(0, 0));
            }
            // 保存图片信息
            byte[] data = RBitmap.ToBytes(bitmap);
            //if(RResourceManager.IsColoPremultiplied) {
            //   int colorLength = data.Length;
            //   for(int n = 0; n < colorLength; n += 4) {
            //      float a = (float)data[n + 3];
            //      data[n] = (byte)(((float)data[n] * a) / 255.0f);
            //      data[n + 1] = (byte)(((float)data[n + 1] * a) / 255.0f);
            //      data[n + 2] = (byte)(((float)data[n + 2] * a) / 255.0f);
            //   }
            //} else if(RResourceManager.IsColoSkipProcess) {
            //   int skipAlpha = RResourceManager.ColoSkipAlpha;
            //   int colorLength = data.Length;
            //   for(int n = 0; n < colorLength; n += 4) {
            //      if(data[n + 3] < skipAlpha) {
            //         data[n] = 0;
            //         data[n + 1] = 0;
            //         data[n + 2] = 0;
            //         data[n + 3] = 0;
            //      }
            //   }
            //}
            byte[] dataResult = new byte[4096 + data.Length * 2];
            int    length     = RCompressJpg.Compress(dataResult, 0, dataResult.Length, data, 0, data.Length, bitmap.Width, bitmap.Height, _qualityColor, 1);

            output.WriteBytes(dataResult, 0, length);
            // 释放图片
            if (bitmap != _bitmap)
            {
                bitmap.Dispose();
                bitmap = null;
            }
        }
示例#3
0
        //============================================================
        // <T>序列化数据内容到输出流中。</T>
        //
        // @param output 输出流
        //============================================================
        public override void Serialize(IOutput output)
        {
            // 处理位图
            Bitmap bitmap = _bitmap;

            if ((_validLocation.X != 0) || (_validLocation.Y != 0) || (_validSize.Width != _bitmap.Width) || ((_validSize.Height != _bitmap.Height)))
            {
                bitmap = new Bitmap(_validSize.Width, _validSize.Height, PixelFormat.Format32bppArgb);
                // 复制图片
                RBitmap.Copy(_bitmap, new SIntRectangle(_validLocation.X, _validLocation.Y, _validSize.Width, _validSize.Height), bitmap, new SIntPoint2(0, 0));
            }
            // 写入宽度和高度
            int width  = _bitmap.Width;
            int height = _bitmap.Height;

            output.WriteInt16((short)width);
            output.WriteInt16((short)height);
            // 写入有效区域
            output.WriteInt16((short)_validLocation.X);
            output.WriteInt16((short)_validLocation.Y);
            output.WriteInt16((short)_validSize.Width);
            output.WriteInt16((short)_validSize.Height);
            // 检测是否有Aplah值
            bool channelA = RBitmap.HasChannel(bitmap, EBitmapChannel.A);

            if (channelA)
            {
                output.WriteInt8(2);
            }
            else
            {
                output.WriteInt8(1);
            }
            // 保存图片信息
            byte[] data = RBitmap.ToBytes(bitmap);
            //if(RResourceManager.IsColoPremultiplied) {
            //   int colorLength = data.Length;
            //   for (int n = 0; n < colorLength; n += 4) {
            //      float a = (float)data[n + 3];
            //      data[n    ] = (byte)(((float)data[n    ] * a) / 255.0f);
            //      data[n + 1] = (byte)(((float)data[n + 1] * a) / 255.0f);
            //      data[n + 2] = (byte)(((float)data[n + 2] * a) / 255.0f);
            //   }
            //}else if(RResourceManager.IsColoSkipProcess) {
            //   int skipAlpha = RResourceManager.ColoSkipAlpha;
            //   int colorLength = data.Length;
            //   for(int n = 0; n < colorLength; n += 4) {
            //      if(data[n + 3] < skipAlpha) {
            //         data[n] = 0;
            //         data[n + 1] = 0;
            //         data[n + 2] = 0;
            //         data[n + 3] = 0;
            //      }
            //   }
            //}
            byte[] dataResult = new byte[4096 + data.Length * 2];
            int    length     = RCompressJpg.Compress(dataResult, 0, dataResult.Length, data, 0, data.Length, bitmap.Width, bitmap.Height, _qualityColor, 1);

            output.WriteInt32(length);
            output.WriteBytes(dataResult, 0, length);
            // 保存图片A信息
            if (channelA)
            {
                length = RCompressJpg.Compress(dataResult, 0, dataResult.Length, data, 0, data.Length, bitmap.Width, bitmap.Height, _qualityAlpha, 3);
                output.WriteInt32(length);
                output.WriteBytes(dataResult, 0, length);
            }
            // 释放图片
            if (bitmap != _bitmap)
            {
                bitmap.Dispose();
                bitmap = null;
            }
        }