internal bool ReadFrames() { //Png header, 8 bytes. if (!InternalStream.ReadBytes(8).SequenceEqual(new byte[] { 137, 80, 78, 71, 13, 10, 26, 10 })) { throw new Exception("Invalid file format, expected PNG signature not found."); } //IHDR chunk, 25 bytes. Ihdr = IhdrChunk.Read(InternalStream); //aCTl chunk, 16 bytes. Actl = ActlChunk.Read(InternalStream); //If there's no animation control chunk, it's a normal Png. if (Actl == null) { return(false); } var masterSequence = 0; var frameGroupId = -1; //Read frames. while (InternalStream.CanRead) { //Tries to read any chunk, except IEND. var chunk = Chunk.Read(InternalStream, masterSequence++); //End reached, prematurely or not. if (chunk == null || chunk.ChunkType == "IEND") { break; } //Chunks can be grouped into frames. if (new[] { "fcTL", "fdAT", "IDAT" }.Contains(chunk.ChunkType)) { if (chunk.ChunkType == "fcTL") { frameGroupId++; } chunk.FrameGroupId = frameGroupId; } Chunks.Add(chunk); } return(true); }