【发布时间】:2018-03-30 00:46:01
【问题描述】:
我正在开发一个 Windows 窗体应用程序,其中我需要做的一件事是从 .img 文件中提取图像。我能够读取普通的 jpg 和 png 文件,但不能读取 .img 文件。
我在互联网上找不到太多关于此的信息。我确实在 msdn 上找到了一些代码,并试图让它工作。下面是抛出的代码和异常。
FileInfo file = new FileInfo(FilePath.Text);
FileStream f1 = new FileStream(FilePath.Text, FileMode.Open,
FileAccess.Read, FileShare.Read);
byte[] BytesOfPic = new byte[Convert.ToInt32(file.Length)];
f1.Read(BytesOfPic, 0, Convert.ToInt32(file.Length));
MemoryStream mStream = new MemoryStream();
mStream.Write(BytesOfPic, 0, Convert.ToInt32(BytesOfPic.Length));
Bitmap bm = new Bitmap(mStream, false);
mStream.Dispose();
// ImageBox is name of a PictureBox
ImageBox.image = bm; // this line is throwing the error
捕捉到异常
System.ArgumentException:参数无效。 在 System.Drawing.Bitmap..ctor(流流,布尔值 useIcm) 在 C:\Users\tiwar\Desktop\A02-Stegnography\A02-Stegnography\Form1.cs:line 65 中的 A02_Stegnography.Form1.ReadImgFile() 处
如果这是一个愚蠢的问题,我很抱歉。我希望我已经提供了足够的信息,但如果我还没有,请告诉我。
【问题讨论】:
-
img不是你可以用内存流打开的图像文件 -
是的,这就是为什么我用文件流打开它,在字节数组中读取它,然后用 MemoryStream 将它写入位图。
-
,哎呀,没看到!
-
该错误意味着您的流为空
-
img文件是什么图片? System.Drawing.Bitmap 仅支持certain file formats
标签: c# .net winforms bitmap picturebox