仅从流C#XP无效的参数创建图像或位图 [英] Invalid parameter creating image or bitmap from stream c# XP only

查看:43
本文介绍了仅从流C#XP无效的参数创建图像或位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我的工作很标准。我通过调用资源上的GetManifestResourceStream从嵌入式资源中创建一些图像,并为其提供.ico文件的路径:

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"));

然后使用位图在我的表单上显示图像。这在Windows 7和8上始终可以完美运行,但是现在当我尝试在XP SP3框上运行该应用程序时,在将流转换为位图的行上看到无效参数。我也尝试使用Image.FromStream,但结果相同。

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.

图标文件来自此应用程序的原始版本,该应用程序是为Visual Basic中的XP编写的。我相信它们是在VB中手动生成的。我已经回收了所有这些图标,以用C#重写此应用程序。这是我第一次遇到问题。

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.

推荐答案

感谢所有建议。我确实尝试将代码分成几行,实际上是从流中创建位图。在几个不同的XP系统上都失败了,它们都运行了安装了.NET 4框架的SP3。

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.

将原始ico文件转换为png文件,然后将其转换为位图,图像质量没有明显损失。

Converting the original ico files to png files and then converting them to bitmap works, with no noticeable loss of quality in the images.

这篇关于仅从流C#XP无效的参数创建图像或位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆