Beispiel #1
0
        public override void SaveToStream(Stream aStream, int aStart, int aEnd)
        {
            base.SaveToStream(aStream, aStart, aEnd);

            // 图像不能直接写流,会导致流前面部分数据错误
            using (MemoryStream vImgStream = new MemoryStream())
            {
                using (Bitmap bitmap = new Bitmap(FImage))  // 解决GDI+ 中发生一般性错误,因为该文件仍保留锁定对于对象的生存期
                {
                    bitmap.Save(vImgStream, ImageFormat.Bmp);
                }

                // write bitmap data size
                uint   vSize   = (uint)vImgStream.Length;
                byte[] vBuffer = BitConverter.GetBytes(vSize);
                aStream.Write(vBuffer, 0, vBuffer.Length);

                vBuffer = new byte[vImgStream.Length];
                vImgStream.Seek(0, SeekOrigin.Begin);
                vImgStream.Read(vBuffer, 0, vBuffer.Length);

                aStream.Write(vBuffer, 0, vBuffer.Length);
            }

            FShapeManager.SaveToStream(aStream);
        }
        public override void SaveToStreamRange(Stream aStream, int aStart, int aEnd)
        {
            base.SaveToStreamRange(aStream, aStart, aEnd);

            // 图像不能直接写流,会导致流前面部分数据错误
            using (MemoryStream vImgStream = new MemoryStream())
            {
                using (Bitmap vBitmap = new Bitmap(FImage.Width, FImage.Height))  // 解决GDI+ 中发生一般性错误,因为该文件仍保留锁定对于对象的生存期
                {
                    using (Graphics vGraphic = Graphics.FromImage(vBitmap))
                    {
                        vGraphic.Clear(Color.White);
                        vGraphic.DrawImage(FImage, 0, 0);
                    }

                    vBitmap.Save(vImgStream, ImageFormat.Bmp);
                }

                // write bitmap data size
                uint   vSize   = (uint)vImgStream.Length;
                byte[] vBuffer = BitConverter.GetBytes(vSize);
                aStream.Write(vBuffer, 0, vBuffer.Length);

                vBuffer = new byte[vImgStream.Length];
                vImgStream.Seek(0, SeekOrigin.Begin);
                vImgStream.Read(vBuffer, 0, vBuffer.Length);

                aStream.Write(vBuffer, 0, vBuffer.Length);
            }

            FShapeManager.SaveToStream(aStream);
        }