/// <summary> /// Creates a new chunk with the specified data (which must include the chunk type in /// the first four bytes). /// </summary> /// <param name="data">The chunk data.</param> /// <param name="image">The parent image.</param> public Chunk(byte[] data, PNGImage image) { if (image == null) { throw new ArgumentNullException("The image must not be null."); } _image = image; ByteStreamReader bs = new ByteStreamReader(data); _type = Utils.ReadString(bs, 4); this.AssertChunkType(_type); if (!image.Classes.ContainsKey(_type)) { _data = data; } }
public zTXtChunk(byte[] data, PNGImage image) : base(data, image) { int i = 0; while (data[i + 4] != 0) { i++; } this.Keyword = ASCIIEncoding.ASCII.GetString(data, 4, i); this.CompressionMethod = (CompressionMethod)data[i + 5]; ByteStreamReader bs = new ByteStreamReader(data); bs.Seek(i + 6, SeekOrigin.Begin); InflaterInputStream iis = new InflaterInputStream(bs, new Inflater(), data.Length - 4 - i - 2); StringBuilder sb = new StringBuilder(); while (iis.Available == 1) { int b = iis.ReadByte(); if (b == -1) { break; } sb.Append(System.Text.ASCIIEncoding.ASCII.GetChars(new byte[] { (byte)b })[0]); } this.Text = sb.ToString(); iis.Close(); bs.Close(); }