public static void SetPPM(PNGFile aFile, uint aXPPM, uint aYPPM) { int pos = aFile.FindChunk(EChunkType.pHYs); PNGChunk chunk; if (pos > 0) { chunk = aFile.chunks[pos]; if (chunk.data == null || chunk.data.Length < 9) { throw new System.Exception("PNG: pHYs chunk data size is too small. It should be at least 9 bytes"); } } else { chunk = new PNGChunk(); chunk.type = EChunkType.pHYs; chunk.length = 9; chunk.data = new byte[9]; aFile.chunks.Insert(1, chunk); } var data = chunk.data; data[0] = (byte)((aXPPM >> 24) & 0xFF); data[1] = (byte)((aXPPM >> 16) & 0xFF); data[2] = (byte)((aXPPM >> 8) & 0xFF); data[3] = (byte)((aXPPM) & 0xFF); data[4] = (byte)((aYPPM >> 24) & 0xFF); data[5] = (byte)((aYPPM >> 16) & 0xFF); data[6] = (byte)((aYPPM >> 8) & 0xFF); data[7] = (byte)((aYPPM) & 0xFF); data[8] = 1; chunk.crc = chunk.CalcCRC(); }