private void ReadFrom(BinaryReader br) { // 1. Image type var imageType = (ImageInfoType)br.ReadByte(); ImageInfo = new ImageInfo(imageType); if (imageType == ImageInfoType.None) { return; } // 2. How multi-frame image is saved bool savedAsSingleImage = imageType == ImageInfoType.SingleImage || br.ReadBoolean(); // 3. Main/single image (if any) if (savedAsSingleImage) { if (imageType == ImageInfoType.Icon) { ImageInfo.Icon = SerializationHelper.ReadIcon(br); } else { ImageInfo.Image = SerializationHelper.ReadImage(br); } } ReadMeta(br, ImageInfo); if (imageType == ImageInfoType.SingleImage || imageType == ImageInfoType.Icon && ImageInfo.Icon.GetImagesCount() <= 1) { return; } // 4. Frames (if any) int len = br.ReadInt32(); var frames = new ImageFrameInfo[len]; Bitmap[] frameImages = savedAsSingleImage ? imageType == ImageInfoType.Icon ? ImageInfo.Icon.ExtractBitmaps() : ((Bitmap)ImageInfo.Image).ExtractBitmaps() : new Bitmap[len]; Debug.Assert(frameImages.Length == frames.Length); for (int i = 0; i < len; i++) { var frame = new ImageFrameInfo(frameImages[i]); frames[i] = frame; if (!savedAsSingleImage) { frame.Image = SerializationHelper.ReadImage(br); } ReadMeta(br, frame); if (imageType == ImageInfoType.Animation) { frame.Duration = br.ReadInt32(); } } ImageInfo.Frames = frames; }
private void ReadFrom(BinaryReader br) { var result = new BitmapDataInfo(); // 1. Bitmap result.BackingImage = (Bitmap)SerializationHelper.ReadImage(br); // 2. Data result.BitmapData = new BitmapData { Width = br.ReadInt32(), Height = br.ReadInt32(), Stride = br.ReadInt32(), PixelFormat = (PixelFormat)br.ReadInt32() }; BitmapDataInfo = result; }
private void ReadFrom(BinaryReader br) { var result = new GraphicsInfo(); // 1. Bitmap result.GraphicsImage = (Bitmap)SerializationHelper.ReadImage(br); // 2. Transformation matrix var elements = (float[])BinarySerializer.DeserializeByReader(br); result.Transform = new Matrix(elements[0], elements[1], elements[2], elements[3], elements[4], elements[5]); // 3. Meta result.OriginalVisibleClipBounds = new Rectangle(br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32()); result.TransformedVisibleClipBounds = new RectangleF(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); result.PageUnit = (GraphicsUnit)br.ReadInt32(); result.Resolution = new PointF(br.ReadSingle(), br.ReadSingle()); GraphicsInfo = result; }