How can I know what image format I get from a stream?

后端 未结 4 1215
南笙
南笙 2020-11-29 19:59

I get a byte stream from some web service. This byte stream contains the binary date of an image and I\'m using the method below to convert it to an Image instance.

4条回答
  •  长情又很酷
    2020-11-29 20:58

    You may checkout the Image.RawFormat property. So once you load the image from the stream you could test:

    if (ImageFormat.Jpeg.Equals(image.RawFormat))
    {
        // JPEG
    }
    else if (ImageFormat.Png.Equals(image.RawFormat))
    {
        // PNG
    }
    else if (ImageFormat.Gif.Equals(image.RawFormat))
    {
        // GIF
    }
    ... etc
    

提交回复
热议问题