简体   繁体   English

从字节下载图像 stream c#

[英]Download Image from byte stream c#

I need to save the image from the URL link and display it on UI then我需要从 URL 链接保存图像,然后在 UI 上显示

I tried all the approaches I was able to google for that purpose:为此,我尝试了所有可以通过谷歌搜索的方法:

 PictureBox pb = new PictureBox(); 
 pb.Load(imageUrl);

and

using (WebClient wc = new WebClient()) 
{
        byte[] bytes = wc.DownloadData(imageUrl);
        MemoryStream ms = new MemoryStream(bytes);
        Image img = Image.FromStream(ms); 
}

and more...和更多...

But unfortunately, I'm constantly getting ArgumentExceptiom "Parameter is not valid, no matter what way I use to convert byte stream to the Image但不幸的是,我不断收到ArgumentExceptiom “参数无效,无论我用什么方式将字节 stream 转换为Image

PS You can open the link in browser -> it is public. PS您可以在浏览器中打开链接->它是公开的。

UPDATE : Issue was resolved by just removing -rw at the end of the link更新:只需在链接末尾删除-rw即可解决问题

Your File is .WebP File , and Bitmap class doesn't support the WebP format.您的文件是.WebP File ,并且Bitmap class不支持 WebP 格式。

A bitmap consists of the pixel data for a graphics image and its attributes. bitmap 由图形图像的像素数据及其属性组成。 There are many standard formats for saving a bitmap to a file.将 bitmap 保存到文件有许多标准格式。 GDI+ supports the following file formats: BMP, GIF, EXIF, JPG, PNG, and TIFF. GDI+ 支持以下文件格式:BMP、GIF、EXIF、JPG、PNG 和 TIFF。 For more information about supported formats, see Types of Bitmaps.有关支持的格式的更多信息,请参阅位图类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM