Public Overloads Function GetPngSize(png As String) As Size Using fs As New FileStream(png, FileMode.Open) Dim bin(33) As Byte fs.Read(bin, 0, 33) Return GetPngSize(bin) End Using End Function Public Overloads Function GetPngSize(png As IEnumerable(Of Byte)) As Size Dim bin As Byte() = png.Take(33).ToArray() If BitConverter.ToUInt64(bin, 0) <> &HA1A0A0D474E5089UL Then Throw New BadImageFormatException("PNG画像ではありません。") ElseIf BitConverter.ToUInt64(bin, 8) <> &H524448490D000000UL Then Throw New NotSupportedException("IHDR チャンクが存在しません。") End If Dim width As Integer = IPAddress.HostToNetworkOrder(BitConverter.ToInt32(bin, 16)) Dim height As Integer = IPAddress.HostToNetworkOrder(BitConverter.ToInt32(bin, 20)) 'Dim bitDepth As Byte = bin(24) 'Dim colorType As Byte = bin(25) 'Dim compressionMethod As Byte = bin(26) 'Dim filterMethod As Byte = bin(27) 'Dim interlaceMethod As Byte = bin(28) 'Dim CRC As UInteger = BitConverter.ToUInt32(bin, 29) Return New Size(width, height) End Function