从 asp.net 访问 ActiveX 方法 (C#)

发布于 2024-09-08 10:10:30 字数 1079 浏览 1 评论 0原文

我编写了一个 activex 用户控件来从用户的剪贴板获取图像。我有一种方法来获取该图像的字节流。我想将其嵌入到 asp.net webforms 页面(C#)中。

我不确定如何使用 c# 从 asp.net 页面的“代码隐藏”部分调用此方法。我无法从“代码隐藏”部分访问该对象。

我试图通过使用 Javascript 来完成此操作,但我不断收到错误:

Microsoft JScript 运行时错误:'ScreenCapMod1' 未定义

这是 HTML 代码:

    <div id="panelScn" style="height:258px;">

        <object id="ScreenCapMod1" name="ScreenCapMod1" height="812" width="689"
            classid="ScreencaptureActiveX.dll#Screencapture_ActiveX.ScreenCapModule">
        </object>
     <input type=button value="Click me" onClick="doScript();">

函数 doScript() { ScreenCapMod1.getScreenshot(); }

这是获取屏幕截图方法的代码:

    public byte[] getScreenshot()
    {
        if (picBoxImagePrev.Image != null)
        {
            MemoryStream stream = new MemoryStream();
            scaledScreenCapture.Save(stream, ImageFormat.Png);
            imgStream = stream.ToArray();
        }
        return imgStream;
    }

I have written an activex user control to get an image from a user's clipboard. I have a method to get the byte stream for this image. I want to embed this into a asp.net webforms page (C#).

I am not sure how to call this method from the "code behind" portion of the asp.net page by using c#. I am not able to access the object from the "code behind" portion.

I am trying to accompish this by using Javascript but I keep getting the error:

Microsoft JScript runtime error: 'ScreenCapMod1' is undefined

This is the HTML code:

    <div id="panelScn" style="height:258px;">

        <object id="ScreenCapMod1" name="ScreenCapMod1" height="812" width="689"
            classid="ScreencaptureActiveX.dll#Screencapture_ActiveX.ScreenCapModule">
        </object>
     <input type=button value="Click me" onClick="doScript();">

function doScript()
{
ScreenCapMod1.getScreenshot();
}

This is the code for the get screenshot method:

    public byte[] getScreenshot()
    {
        if (picBoxImagePrev.Image != null)
        {
            MemoryStream stream = new MemoryStream();
            scaledScreenCapture.Save(stream, ImageFormat.Png);
            imgStream = stream.ToArray();
        }
        return imgStream;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巨坚强 2024-09-15 10:10:30

ActiveX 控件将在客户端运行,因此您需要某种方法将数据从客户端推送到服务器。标准 Web 服务应该可以为您完成此任务。

The ActiveX control will run on the client side, so you need some way of pushing that data from the client to the server. A standard web service should accomplish this for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文