WebP image with C# ImageFormat class

前端 未结 2 2021
后悔当初
后悔当初 2021-01-24 00:27

I\'m downloading in image from web to save it locally. It works great with any other image formats but it this method below fails with an argument exception when I try to read a

2条回答
  •  不思量自难忘°
    2021-01-24 01:00

    The base class libraries won't help you to deal with WebP images. However, if you only want to save the received file to the disk, you don't have to even know that you are dealing with a WebP images. You can simply treat the received data as a binary blob and dump it to a file, for example using Stream.CopyTo and a FileStream.

    The Content-Type HTTP header will give you the mime type of the file you're downloading, and the Content-Disposition header can provide you with a filename and extension (though you might have to do some parsing). You can access those using HttpWebResponse.ContentType and HttpWebResponse.Headers["Content-Disposition"].

提交回复
热议问题