加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 从资源文件读取Cursor时,会抛出一个ArgumentException异常

发布时间:2020-12-15 07:49:02 所属栏目:百科 来源:网络整理
导读:当我使用MemoryStream从资源文件加载游标时,我收到一个ArgumentException.这是我用来加载光标的代码: Cursor myCursor = new Cursor(new MemoryStream(WaterforMGC.Properties.Resources.waterspray));Cursor = myCursor; 但是我收到错误.我不知道是什么错,
当我使用MemoryStream从资源文件加载游标时,我收到一个ArgumentException.这是我用来加载光标的代码:
Cursor myCursor
    = new Cursor(new MemoryStream(WaterforMGC.Properties.Resources.waterspray));
Cursor = myCursor;

但是我收到错误.我不知道是什么错,我甚至改变了Cursor = myCursor; to this.Cursor = myCursor;这给了我同样的错误.我试过gameform.Cursor = myCursor;但是这根本就不行.

System.ArgumentException: Image format is not valid. The image file may be corrupted.
Parameter name: stream ---> System.Runtime.InteropServices.COMException (0x800A01E1): Exception from HRESULT: 0x800A01E1 (CTL_E_INVALIDPICTURE)
   at System.Windows.Forms.UnsafeNativeMethods.IPersistStream.Load(IStream pstm)
   at System.Windows.Forms.Cursor.LoadPicture(IStream stream)
   --- End of inner exception stack trace ---
   at System.Windows.Forms.Cursor.LoadPicture(IStream stream)
   at WaterforMGC.gameform.Form1_Load(Object sender,EventArgs e) in C:UsersJanDocumentsVisual Studio 2008ProjectsWaterforMGCWaterforMGCForm1.cs:line 39
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)

解决方法

问题在例外的第一行中阐明:

System.ArgumentException: Image format is not valid. The image file
may be corrupted.

您确定要加载的图像处于未破坏的状态,为compatible with the image format for cursors?

The Cursor class does not support animated cursors (.ani files) or cursors with colors other than black and white.

你有任何其他地方加载光标图像,它的工作原理?你可能能够解决这个问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读