简体   繁体   English

从Stream转换System.Drawing.Image-参数无效

[英]Convert System.Drawing.Image from Stream — Parameter not valid

I am trying to convert 我正在尝试转换

System.Drawing.Image from Stream 流中的System.Drawing.Image

but its throwing Parameter not valid exception. 但其throw Parameter not valid exception.

 Stream p_sImageStream = GenerateStreamFromString(p_sImage);
 System.Drawing.Image oIM = Bitmap.FromStream(p_sImageStream);

my p_sImage is "56427673422d0cbd5dfdfebc_M-19__wide-1.JPG" 我的p_sImage是"56427673422d0cbd5dfdfebc_M-19__wide-1.JPG"

The parameter to GenerateStreamFromString is not a filename, it's expected to contain the actual data. GenerateStreamFromString的参数不是文件名,应该包含实际数据。

If you have the filename of a JPEG file, use File.OpenRead to get a stream you can pass to Bitmap.FromStream , or else just use new Bitmap(filename) -- this constructor overload opens and reads a file. 如果您具有JPEG文件的文件名,请使用File.OpenRead获取可以传递给Bitmap.FromStream的流,或者仅使用new Bitmap(filename) -此构造函数重载将打开并读取文件。

Try this 尝试这个

string p_sImage = @"c:\temp\56427673422d0cbd5dfdfebc_M-19__wide-1.JPG";
FileStream stream = new FileStream(p_sImage, FileMode.Open);
System.Drawing.Image oIM = Bitmap.FromStream(stream);

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

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