//============================================================
        // <T>导出资源。</T>
        //============================================================
        public void Merge()
        {
            // 计算范围
            int             clipCount  = ClipNotEmptyCount;
            FRsResourceClip firstClip  = FristClip;
            int             frameCount = 0;

            if (null != firstClip)
            {
                frameCount = firstClip.FrameCount;
            }
            else
            {
                RMoCore.TrackConsole.Write(this, "Merge", "Animatioin is valid, first clip is empty. (code={0})", Code);
                return;
            }
            int width  = _size.Width * frameCount;
            int height = _size.Height * clipCount;

            // 计算是否合并
            using (Bitmap bitmap = new Bitmap(width, height)) {
                // 合并图片
                int y = 0;
                foreach (FRsResourceClip clip in _clips)
                {
                    if (clip != null)
                    {
                        if (!clip.Frames.IsEmpty())
                        {
                            for (int x = 0; x < frameCount; x++)
                            {
                                FRsResourceFrame frame = clip.Frames[x];
                                int cx = _size.Width * x;
                                int cy = _size.Height * y;
                                if (frame.ValidBitmap != null)
                                {
                                    frame.MergeLocation.Set(cx, cy);
                                    RBitmap.Copy(frame.ValidBitmap, new SIntRectangle(0, 0, frame.ValidBitmap.Width, frame.ValidBitmap.Height), bitmap, frame.MergeLocation);
                                }
                            }
                            y++;
                        }
                    }
                }
                // 存储图片
                _mergeFileName = RContent2dManager.ResourceConsole.MergeDirectory + "\\" + Code + ".png";
                RDirectory.MakeDirectoriesForFile(_mergeFileName);
                bitmap.Save(_mergeFileName);
                _mergeSize.Set(bitmap.Width, bitmap.Height);
            }
        }
Exemple #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;
            }
        }
Exemple #3
0
        //============================================================
        // <T>序列化数据内容到输出流中。</T>
        //
        // @param output 输出流
        //============================================================
        public void Serialize2(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);
            // 获得编码器
            ImageCodecInfo jpgCodec = RBitmap.FindImageCodecInfo(EBitmap.Jpg);
            // 检测是否有Aplah值
            bool channelA = RBitmap.HasChannel(bitmap, EBitmapChannel.A);

            if (channelA)
            {
                output.WriteInt8(2);
            }
            else
            {
                output.WriteInt8(1);
            }
            // 保存图片RGB信息
            using (Bitmap bitmapRgb = new Bitmap(_validSize.Width, _validSize.Height, PixelFormat.Format32bppRgb)) {
                EncoderParameters parameters = new EncoderParameters(1);
                parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)_qualityColor);
                RBitmap.CopyChannels(bitmap, bitmapRgb, EBitmapChannels.RGB);
                using (MemoryStream buffer = new MemoryStream()) {
                    bitmapRgb.Save(buffer, jpgCodec, parameters);
                    byte[] data = buffer.ToArray();
                    output.WriteInt32(data.Length);
                    output.WriteBytes(data, 0, data.Length);
                }
            }
            // 保存图片A信息
            if (channelA)
            {
                using (Bitmap bitmapA = new Bitmap(_validSize.Width, _validSize.Height, PixelFormat.Format32bppRgb)) {
                    EncoderParameters parameters = new EncoderParameters(1);
                    parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)_qualityAlpha);
                    RBitmap.CopyChannel(bitmap, EBitmapChannel.A, bitmapA, EBitmapChannels.RGB, _validAlpha);
                    using (MemoryStream buffer = new MemoryStream()) {
                        bitmapA.Save(buffer, jpgCodec, parameters);
                        byte[] data = buffer.ToArray();
                        output.WriteInt32(data.Length);
                        output.WriteBytes(data, 0, data.Length);
                    }
                }
            }
            // 释放图片
            if (bitmap != _bitmap)
            {
                bitmap.Dispose();
                bitmap = null;
            }
        }
Exemple #4
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;
            }
        }