我使用下面的代码将本地路径中的png图像(D:\ CURR PROJECT \ NewUIChanges \ Htmlfile \ round1.png)转换为bytes.I我得到一个null execption即img stream is null.Plz hep我
Stream imgStream;
imgStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("NewUIChanges.Htmlfile.round1.png");
byte[] data = new byte[(int)imgStream.Length];
int offset = 0;
while (offset < data.Length)
{
int bytesRead = imgStream.Read(data, offset, data.Length - offset);
if (bytesRead <= 0)
{
throw new EndOfStreamException("Stream wasn't as long as it claimed");
}
offset += bytesRead;
}
答案 0 :(得分:0)
此行产生问题。 imgStream为null。
imgStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("NewUIChanges.Htmlfile.round1.png");
检查图像路径。可能是错的。
答案 1 :(得分:0)
将图像的构建操作更改为嵌入式资源。