【问题标题】:How to fix color c# DownloadData to byte array如何将颜色c#DownloadData修复为字节数组
【发布时间】:2021-10-06 07:37:56
【问题描述】:

我正在尝试下载图像(jpg、jpeg 和 png)。但是当大小超过 200,000 字节时,我会得到一张黑白图片。

我的代码:

byte[] fileBytes;
try 
{ 
   path = url + path; 
   fileBytes = (new WebClient()).DownloadData(path); 
}
catch
{
   path = urlNoimagefound;
   fileBytes = (new WebClient()).DownloadData(path);
}
... 
// and then I add byte in rdlc

由于字节数组的大小,我想我得到一张黑白图片。

如何解决?

谢谢。

【问题讨论】:

  • 您是否遇到了某种异常?
  • 对不起,你能解释更多吗?什么是异常?
  • 对不起,我的错,我有路径例外。我正在编辑这篇文章。
  • 如果它到达catch方法,那么你应该让它通过catch (Exception ex)产生异常,然后一旦你进入catch部分,ex就会有错误数据。

标签: c#


【解决方案1】:

我不确定如何处理 DownloadData,但这是我在旧项目中使用的 sn-p:

private static Image DownloadImage(string source)
{
    using (var webClient = new WebClient())
    using (var stream = webClient.OpenRead(source))
    {
        return Image.FromStream(stream);
    }
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-19
  • 1970-01-01
  • 2013-01-14
相关资源
最近更新 更多