示例#1
0
 /// <summary>
 /// For testing, see if we can write a png ourself that can be opened by .Net png.
 /// </summary>
 /// <param name="image">The image to write to png format</param>
 /// <param name="fileName">The string fileName</param>
 public void Write(Bitmap image, string fileName)
 {
     if (File.Exists(fileName)) File.Delete(fileName);
     Stream f = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write, FileShare.None, 1000000);
     WriteSignature(f);
     PngHeader header = new PngHeader(image.Width, image.Height);
     header.Write(f);
     WriteSrgb(f);
     byte[] refImage = GetBytesFromImage(image);
     byte[] filtered = Filter(refImage, 0, refImage.Length, image.Width * 4);
     byte[] compressed = Deflate.Compress(filtered);
     WriteIDat(f, compressed);
     WriteEnd(f);
     f.Flush();
     f.Close();
 }
示例#2
0
        /// <summary>
        /// Reads the important content from the stream of bytes
        /// </summary>
        /// <param name="stream"></param>
        public static PngHeader FromBytes(Stream stream)
        {
            byte[] vals = new byte[25];
            stream.Read(vals, 0, 25);
            int w = (int)BitConverter.ToUInt32(vals, 9);
            int h = (int)BitConverter.ToUInt32(vals, 13);

            PngHeader result = new PngHeader(w, h);
            result.BitDepth = (BitDepth)vals[17];
            result.ColorType = (ColorType)vals[18];
            result.InterlaceMethod = (InterlaceMethod)vals[21];
            return result;
        }