コード例 #1
0
        public static AbstractChunk From(Stream stream)
        {
            AbstractChunk chunk;
            Span <byte>   buffer = stackalloc byte[4];

            stream.Read(buffer);
            if (BitConverter.IsLittleEndian)
            {
                buffer.Reverse();
            }
            int length = (int)Unsafe.ReadUnaligned <uint>(ref MemoryMarshal.GetReference(buffer));

            stream.Read(buffer);
            string type = Encoding.ASCII.GetString(buffer);

            switch (type)
            {
            case "tEXt":
                chunk = new TextualChunk();
                break;

            default:
                chunk = new RawChunk();
                break;
            }
            chunk.Length = length;
            chunk.Type   = type;
            chunk.HandleChunkData(stream);
            stream.Read(buffer);
            if (BitConverter.IsLittleEndian)
            {
                buffer.Reverse();
            }
            chunk.Crc = Unsafe.ReadUnaligned <uint>(ref MemoryMarshal.GetReference(buffer));
            return(chunk);
        }
コード例 #2
0
ファイル: PNGImage.cs プロジェクト: SitamMatt/PhotoOrganizer
        public void AddTextualData(string keyword, string text)
        {
            TextualChunk textualChunk = new TextualChunk(keyword, text);

            Chunks.Insert(Chunks.Count - 2, textualChunk);
        }