SaveToStream() public method

Saves the image to a filestream.
public SaveToStream ( Bitmap image, BinaryWriter writer ) : void
image System.Drawing.Bitmap The image to save.
writer System.IO.BinaryWriter The System.IO.BinaryWriter to use.
return void
示例#1
0
        /// <summary>
        /// Savbes the tileset to a separate file.
        /// </summary>
        /// <param name="filename">The filename to save to.</param>
        public void Save(string filename)
        {
            using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(filename)))
            {
                // save header data:
                writer.Write(".rts".ToCharArray());
                writer.Write(_version);
                writer.Write((short)Tiles.Count);
                writer.Write(TileWidth);
                writer.Write(TileHeight);
                writer.Write((short)32);
                writer.Write(_compression);

                foreach (Tile t in Tiles)
                    if (t.Obstructions.Count > 0) _hasObstruct = 1;

                writer.Write(_hasObstruct);
                writer.Write(new byte[240]);

                // save tile pixels:
                BitmapSaver saver = new BitmapSaver(TileWidth, TileHeight);
                foreach (Tile tile in Tiles)
                    saver.SaveToStream(tile.Graphic, writer);

                // save tile info:
                foreach (Tile t in Tiles)
                {
                    writer.Write(new byte());
                    writer.Write(t.Animated);
                    writer.Write(t.NextAnim);
                    writer.Write(t.Delay);
                    writer.Write(new byte());
                    writer.Write((byte)2);
                    writer.Write((short)t.Obstructions.Count);
                    writer.Write((short)t.Name.Length);
                    writer.Write(new byte[20]);
                    writer.Write(t.Name.ToCharArray());
                    foreach (Line l in t.Obstructions)
                    {
                        writer.Write(l.X1); writer.Write(l.Y1);
                        writer.Write(l.X2); writer.Write(l.Y2);
                    }
                }

                writer.Flush();
            }
        }
示例#2
0
        /// <summary>
        /// Saves the windowstyle to the Sphere .rws format.
        /// </summary>
        /// <param name="filename">The path in which to save to.</param>
        public void Save(string filename)
        {
            using (BinaryWriter writer = new BinaryWriter(File.Open(filename, FileMode.Create)))
            {
                writer.Write(_sig.ToCharArray());
                writer.Write(_version);
                writer.Write(_edgeWidth);
                writer.Write(_backgroundMode);
                foreach (RGBA color in _edgeColors) color.SaveData(writer);
                foreach (byte edge in _edgeOffset) writer.Write(edge);
                writer.Write(new byte[36]);

                switch (_version)
                {
                    case 2:
                        foreach (Bitmap b in _images)
                        {
                            writer.Write((short)b.Width);
                            writer.Write((short)b.Height);
                            BitmapSaver saver = new BitmapSaver(b.Width, b.Height);
                            saver.SaveToStream(b, writer);
                        }
                        break;
                }

                writer.Flush();
            }
        }
示例#3
0
        /// <summary>
        /// Saves the Spriteset to the filename.
        /// </summary>
        /// <param name="filename">The filename to store the spriteset.</param>
        public void Save(string filename)
        {
            using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(filename)))
            {
                // save header data:
                writer.Write(".rss".ToCharArray());
                writer.Write(_version);
                writer.Write((short)_images.Count);
                writer.Write(_frameWidth);
                writer.Write(_frameHeight);
                writer.Write((short)_directions.Count);

                // save the sprite base:
                writer.Write(_spriteBase.X1);
                writer.Write(_spriteBase.Y1);
                writer.Write(_spriteBase.X2);
                writer.Write(_spriteBase.Y2);

                //reserved:
                writer.Write(new byte[106]);

                switch (_version)
                {
                    case 3:
                        BitmapSaver saver = new BitmapSaver(_frameWidth, _frameHeight);
                        for (short i = 0; i < _images.Count; ++i) saver.SaveToStream(Images[i], writer);
                        foreach (Direction d in _directions)
                        {
                            writer.Write((short)d.Frames.Count);
                            writer.Write(new byte[6]);
                            writer.Write((short)(d.Name.Length + 1));
                            writer.Write((d.Name + "\0").ToCharArray());
                            foreach (Frame f in d.Frames)
                            {
                                writer.Write(f.Index);
                                writer.Write(f.Delay);
                                writer.Write(new byte[4]);
                            }
                        }
                        break;
                }

                writer.Flush();
            }
        }