Exemplo n.º 1
0
        public static ImageGrid Read(BinaryReader reader, Corner2CornerPalette palette)
        {
            bool haveGrid = reader.ReadBoolean();

            if (haveGrid)
            {
                int width  = reader.ReadInt32();
                int height = reader.ReadInt32();

                ImageGrid result = new ImageGrid(width, height);

                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        if (reader.ReadBoolean())
                        {
                            IPaletteItem cell;
                            palette.Find(Color.FromArgb(reader.ReadInt32()), out cell);
                            result[x, y] = cell;
                        }
                    }
                }

                return(result);
            }
            else
            {
                return(null);
            }
        }
        public static bool Load(Stream stream, Corner2CornerProject project)
        {
            using (BinaryReader reader = new BinaryReader(stream))
            {
                if (!HeaderPersistence.Read(reader))
                {
                    stream.Position = 0;
                    return(false);
                }

                Image image = ImagePersistence.Read(reader);
                int   width = reader.ReadInt32();

                int paletteItemCount         = reader.ReadInt32();
                Corner2CornerPalette palette = new Corner2CornerPalette();

                for (int i = 0; i < paletteItemCount; i++)
                {
                    var pi = PaletteItemPersistence.Read(reader);
                    palette.Add(color: pi.Color, text: pi.Text);
                }

                IPaletteItem selectedPaletteItem = PaletteItemPersistence.Read(reader);
                palette.Find(selectedPaletteItem?.Color ?? Color.Empty, out selectedPaletteItem);

                ImageGrid imageGrid = ImageGridPersistence.Read(reader, palette);

                Color gridBackgroundColor = Color.FromArgb(reader.ReadInt32());

                //read everything successfully so populate the project;

                project.Image               = image;
                project.Width               = width;
                project.Palette             = palette;
                project.SelectedPaletteItem = selectedPaletteItem;
                project.ImageGrid           = imageGrid;
                project.GridBackgroundColor = gridBackgroundColor;
                project.ChangeTracking.Track(ChangeTrackingOperation.SetSaved);

                return(true);
            }
        }