如何使用 C# 将光标转换为可以保存到 .resx 文件中的图像?
我正在尝试从 Visual Basic 编译的 dll 文件中读取光标图像。到目前为止,程序可以很好地提取字符串和位图,但它不喜欢提取光标。提取资源后,程序将它们保存在 .resx 文件中,而不是 dll 中。我遇到了一些麻烦,因为我认为 .resx 文件不直接支持游标。
这是我到目前为止所得到的:
[DllImport("user32.dll")]
static extern IntPtr LoadCursor(IntPtr hInstance, uint lpCursorName);
[DllImport("kernel32.dll")]
public static extern IntPtr LoadLibrary(string dllToLoad);
var Lib = LoadLibrary("myLib.dll");
IntPtr cRes = LoadCursor(Lib,101);
Cursor c = new Cursor(cRes);
writer.AddResource("cursor_" + 101, c);
这在其他文件上完美地工作,但是当我尝试使用光标执行此操作时,它会抛出“InvalidOperationException”并表示图像格式无效。它实际上将句柄加载到 Cursor 中没有问题,但当我尝试将其保存为 .resx 时会抛出异常。我尝试将光标作为位图加载,但这只是加载空白图像。 CursorConverter 似乎也不适用于图像。
因此,如果有人对如何解决这个问题有任何想法,请告诉我。谢谢你!
I am trying to read a cursor image from a dll file complied in Visual Basic. So far, the program can pull out strings and bitmaps just fine, but it does not like pulling out cursors. After pulling out the resources, the program then saves them in a .resx file instead of a dll. I am having some trouble because I don't think that .resx files support cursors directly.
Here is what I have so far:
[DllImport("user32.dll")]
static extern IntPtr LoadCursor(IntPtr hInstance, uint lpCursorName);
[DllImport("kernel32.dll")]
public static extern IntPtr LoadLibrary(string dllToLoad);
var Lib = LoadLibrary("myLib.dll");
IntPtr cRes = LoadCursor(Lib,101);
Cursor c = new Cursor(cRes);
writer.AddResource("cursor_" + 101, c);
This works perfectly on other files, but when I try to do this with cursors, it throws an "InvalidOperationException" and says the image format is not valid. It actually loads the handle into Cursor no problem, but will throw the exception when I try to save it as a .resx. I've tried loading the cursor as a bitmap instead, but that just loads a blank image. CursorConverter doesn't appear to work for images either.
So if anyone has any ideas on how to work this out, please let me know. Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
LoadCursor 的文档说它已被 LoadImage 取代。你尝试过使用它吗?
The documentation for LoadCursor says it has been superseded by LoadImage. Have you tried using that?