示例#1
0
        public bool WriteToFile(string path, bool rle = true)
        {
            var bpp = (int)Format;

            using (var writer = new BinaryWriter(File.Create(path)))
            {
                var header = new TGAHeader
                {
                    IdLength        = 0, // The IDLength set to 0 indicates that there is no image identification field in the TGA file
                    ColorMapType    = 0, // a value of 0 indicates that no palette is included
                    BitsPerPixel    = (byte)(bpp * 8),
                    Width           = (short)Width,
                    Height          = (short)Height,
                    DataTypeCode    = DataTypeFor(bpp, rle),
                    ImageDescriptor = (byte)(0x20 | (Format == Format.BGRA ? 8 : 0)) // top-left origin
                };
                WriteTo(writer, header);
                if (!rle)
                {
                    writer.Write(Buffer);
                }
                else
                {
                    UnloadRleData(writer);
                }
            }
            return(true);
        }
示例#2
0
 private static void WriteTo(BinaryWriter writer, TGAHeader header)
 {
     writer.Write(header.IdLength);
     writer.Write(header.ColorMapType);
     writer.Write((byte)header.DataTypeCode);
     writer.Write(header.ColorMapOrigin);
     writer.Write(header.ColorMapLength);
     writer.Write(header.ColorMapDepth);
     writer.Write(header.OriginX);
     writer.Write(header.OriginY);
     writer.Write(header.Width);
     writer.Write(header.Height);
     writer.Write(header.BitsPerPixel);
     writer.Write(header.ImageDescriptor);
 }
示例#3
0
        private static TGAHeader ReadHeader(BinaryReader reader)
        {
            var header = new TGAHeader
            {
                IdLength        = reader.ReadByte(),
                ColorMapType    = reader.ReadByte(),
                DataTypeCode    = (DataType)reader.ReadByte(),
                ColorMapOrigin  = reader.ReadInt16(),
                ColorMapLength  = reader.ReadInt16(),
                ColorMapDepth   = reader.ReadByte(),
                OriginX         = reader.ReadInt16(),
                OriginY         = reader.ReadInt16(),
                Width           = reader.ReadInt16(),
                Height          = reader.ReadInt16(),
                BitsPerPixel    = reader.ReadByte(),
                ImageDescriptor = reader.ReadByte()
            };

            return(header);
        }