问题描述
我在C#编写一个BHO库mybho.dll。我有嵌入的资源文件image.png。我想显示某些页面此图像。根据我读,它应该是这样的:
I have a BHO library mybho.dll written in C#. I have embedded a Resource file "image.png". I'd like to show this image on some pages. According to what I read, it should look like this:
<img src="res://mybho.dll/image.png">
不过,Internet Explorer不会找到图像。我已经试过这一次没有成功:
But Internet Explorer does not find the image. I've tried this one without success:
<img src="res://mybho.dll/#2/image.png">
什么是做正确的方式?
What is the right way to do it?
推荐答案
您混淆的Win32资源和.NET程序集资源。在资源:协议处理程序返回从DLL Win32资源。 .NET资源不会 Win32的资源,因此IE(实际上urlmon.dll中,其中RES:正在实施)。找不到你的图片
You are confusing Win32 resources and .NET assembly resources. the 'res:' protocol handler returns a Win32 resource from a DLL. .NET resources are NOT Win32 resources, and as such IE (Actually urlmon.dll, where res: is implemented) cannot find your image.
你有两种选择:
-
最简单的方法很可能会创建一个Win32资源(* .RES文件)和嵌入它进入托管程序集。首先,创建一个* .RC文件,它指向你的形象。我不知道,但我想你有你的PNG,以BMP格式先转换。然后,编译RC文件转换为二进制资源(与RC - 资源编译器)。最后,为您打造您的托管程序集,使用/ win32res开关添加Win32资源。
The easiest way would probably be to create a Win32 resource (*.res file) and embed it into the managed assembly. First, create a *.RC file, which points to your image. I'm not sure, but I think you'll have to convert your PNG to BMP format first. Then, compile the RC file into a binary resource (with RC - the Resource Compiler). Finally, as you build your managed assembly, use the /win32res switch to add the Win32 resource.
您也可以实现异步可插入协议处理程序。假设你想实现一个新的协议方案:朱利安://image.png。在HKCR\PROTOCOLS\Handler\julien注册,并实现IInternetProtocol(和其他一些协议)。这是不是一件很容易的事(做一次 - 有很多机会犯错误)。
You can also implement a Asynchronous Pluggable Protocol handler. Say you want to implement a new protocol scheme: julien://image.png'. Register it at HKCR\PROTOCOLS\Handler\julien, and implement IInternetProtocol (and few other protocols). This is NOT a very easy task (did it once - there are many opportunities to make mistakes).
这篇关于如何嵌入从BHO网页上的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!