问题
I believe what I am doing is pretty standard. I create some images from embedded resources by calling GetManifestResourceStream on the resource, giving it the path to the .ico file:
Bitmap bmp = new Bitmap(Assembly.GetEntryAssembly().GetManifestResourceStream("MeterView.Resources.unlocked.ico"));
The bitmap is then used to display an image on my form. This has always worked perfectly on Windows 7 and 8, but now when I try to run the app on an XP SP3 box I get "Invalid Parameter" on the line that converts the stream to a bitmap. I also tried using Image.FromStream, but with the same result.
The build action on the resource is set to Embedded Resource. Anyone have any ideas how I can get around this problem? I also tried resetting the stream, that also made no difference.
Thanks in advance for any suggestions.
The icon files came from the original version of this application, which was written for XP in Visual Basic. I believe they were manually generated in VB. I have recycled all of these icons for the rewrite of this application in C#. This is the first time I've run into problems.
回答1:
Thanks for all the suggestions. I did try breaking up the code into individual lines, and it was in fact the creation of the bitmap from the stream. Failed on several different XP systems, all running SP3 with the .NET 4 framework installed.
Converting the original ico files to png files and then converting them to bitmap works, with no noticeable loss of quality in the images.
来源:https://stackoverflow.com/questions/14070249/invalid-parameter-creating-image-or-bitmap-from-stream-c-sharp-xp-only