Ejemplo n.º 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();
 }
Ejemplo n.º 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 = (BitDepths)vals[17];
            result.ColorType = (ColorTypes) vals[18];
            result.InterlaceMethod = (InterlaceMethods) vals[21];
            return result;
        }