【发布时间】:2017-05-07 10:24:03
【问题描述】:
我正在尝试从Byte[] 中保存Image,但我不断被ArgumentException : Parameter is not valid 踢出。我想知道Byte[] 是否太大而无法转换。有限制吗?
代码:
private XImage[] GetImagesFromURL(List<string> lstCutSheetURLs)
{
int itr = lstCutSheetURLs.Count;
XImage[] m_imgCutSheets = new XImage[itr];
using (var webClient = new WebClient())
{
for (int i = 0; i < itr; i++)
{
var imageBytes = webClient.DownloadData(lstCutSheetURLs[i]);
if (imageBytes != null && imageBytes.Length > 0)
{
MemoryStream ms = new MemoryStream();
ImageConverter converter = new ImageConverter();
//
//THIS IS WHERE IT BREAKS EVERY TIME
Image img = (Image)converter.ConvertFrom(imageBytes);
//
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
m_imgCutSheets[i] = XImage.FromStream(ms);
}
}
}
return m_imgCutSheets;
}
Byte[] 最终拥有 458,330 个索引。这样是不是太多了?有没有更好的方法从网站获取图像?我一直在四处寻找,试图找出答案,现在我在这里。
非常感谢任何文章/建议/答案!谢谢。
【问题讨论】:
-
这适用于较小的图像吗?
-
哪一行报错
-
@Trey 此行下方:
//THIS IS WHERE IT BREAKS EVERY TIME. -
@rhughes - 我不知道。我的任务是从网站上提取图像,因此所有源都设置为执行和解决该问题。没有尝试过任何其他图像。相反,我应该说我在测试期间只使用来自一个特定网站的一张特定图像。
-
等一下,你把 PDF 的 byte[] 扔到 ImageConverter 上,对吗?
标签: c# arrays image converter pdfsharp