/// <summary> /// Creates <see cref="JpegImage"/> from stream with an arbitrary image data /// </summary> /// <param name="imageData">Stream containing bytes of image in /// arbitrary format (BMP, Jpeg, GIF, PNG, TIFF, e.t.c)</param> public JpegImage(Stream imageData) { if (imageData is null) { throw new ArgumentNullException(nameof(imageData)); } m_compressedData = new MemoryStream(); imageData.CopyTo(m_compressedData); if (CompressedData.Length <= 2) { throw new ArgumentException("There must be at least two bytes in the image stream", nameof(imageData)); } CompressedData.Seek(0, SeekOrigin.Begin); var first = CompressedData.ReadByte(); var second = CompressedData.ReadByte(); if (!(first == 0xFF) && (second == (int)JpegMarker.SOI)) { throw new ArgumentException("This is not a JPEG stream", nameof(imageData)); } Decompress(); }