无法嵌入类。请改用适用的接口

发布于 2024-10-03 02:08:31 字数 1067 浏览 5 评论 0原文

我正在使用 WIA 将扫描仪中的图像捕获到 Windows 窗体中。这是我正在使用的代码:

private void button2_Click(object sender, EventArgs e)
{
    const string wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}";
    CommonDialogClass wiaDiag = new CommonDialogClass();
    WIA.ImageFile wiaImage = null;

    wiaImage = wiaDiag.ShowAcquireImage(
            WiaDeviceType.UnspecifiedDeviceType,
            WiaImageIntent.GrayscaleIntent,
            WiaImageBias.MaximizeQuality,
            wiaFormatJPEG, true, true, false);

    WIA.Vector vector = wiaImage.FileData;

    Image i = Image.FromStream(new MemoryStream((byte[])vector.get_BinaryData()));
    i.Save(@"D:\prueba1.jpeg");
}

当尝试运行这个小测试时,我收到此错误:

互操作类型“WIA.CommonDialogClass” 无法嵌入。使用适用的 而是接口。

还有这个:

“WIA.CommonDialogClass”没有 包含一个定义 “ShowAcquireImage”且无扩展名 方法“ShowAcquireImage”接受 类型的第一个参数 可以找到“WIA.CommonDialogClass” (您是否缺少 using 指令或 程序集参考?

我猜第二个错误是因为第一个错误而出现的,对吧?

关于如何解决这个问题有什么建议吗?

I'm using WIA to capture an image fron the scanner to the windows form. Here is the code I'm using:

private void button2_Click(object sender, EventArgs e)
{
    const string wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}";
    CommonDialogClass wiaDiag = new CommonDialogClass();
    WIA.ImageFile wiaImage = null;

    wiaImage = wiaDiag.ShowAcquireImage(
            WiaDeviceType.UnspecifiedDeviceType,
            WiaImageIntent.GrayscaleIntent,
            WiaImageBias.MaximizeQuality,
            wiaFormatJPEG, true, true, false);

    WIA.Vector vector = wiaImage.FileData;

    Image i = Image.FromStream(new MemoryStream((byte[])vector.get_BinaryData()));
    i.Save(@"D:\prueba1.jpeg");
}

When trying to run this little test, I get this error:

Interop type 'WIA.CommonDialogClass'
cannot be embedded. Use the applicable
interface instead.

And this:

'WIA.CommonDialogClass' does not
contain a definition for
'ShowAcquireImage' and no extension
method 'ShowAcquireImage' accepting a
first argument of type
'WIA.CommonDialogClass' could be found
(are you missing a using directive or
an assembly reference?

I'm guessing the second error is being risen because of the first error, right?

Any suggestions on how to fix this?

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

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

发布评论

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

评论(3

红ご颜醉 2024-10-10 02:08:31

第二个错误是由第一个错误引起的。嵌入互操作类型功能仅支持嵌入接口,而不支持类。除了将 WIA 引用上的该选项设置为 False 并部署互操作库之外,您还可以像这样修复它:

 WIA.CommonDialog wiaDiag = new WIA.CommonDialog();

不直观,但允许使用 new 运算符创建 COM 接口。您需要为命名空间名称添加前缀,因为 CommonDialog 与 Winforms CommonDialog 类不明确。

The 2nd error is caused by the first one. The Embed Interop Types feature only supports embedding interfaces, not classes. Other than just setting that option on the WIA reference to False and deploy the interop library, you could also fix it like this:

 WIA.CommonDialog wiaDiag = new WIA.CommonDialog();

Unintuitive but creating COM interfaces with the new operator is allowed. You need to prefix the namespace name because CommonDialog is ambiguous with the Winforms CommonDialog class.

月朦胧 2024-10-10 02:08:31

http://digital.ni.com/public.nsf/allkb/4EA929B78B5718238625789D0071F307

发生此错误的原因是新项目中引用的 TestStand API Interop 程序集的 Embed Interop Types 属性的默认值为 true。要解决此错误,请按照以下步骤将“嵌入互操作类型”属性的值更改为 False:

Select the TestStand Interop Assembly reference in the references section of your project in the Solution Explorer.
Find the Embed Interop Types property in the Property Browser, and change the value to False

相关链接:
KnowledgeBase 595FQJPI:我可以将 Visual Studio 2010 与 TestStand 结合使用并调用 .NET Framework 4.0 代码模块吗?

http://digital.ni.com/public.nsf/allkb/4EA929B78B5718238625789D0071F307

This error occurs because the default value is true for the Embed Interop Types property of the TestStand API Interop assembly referenced in the new project. To resolve this error, change the value of the Embed Interop Types property to False by following these steps:

Select the TestStand Interop Assembly reference in the references section of your project in the Solution Explorer.
Find the Embed Interop Types property in the Property Browser, and change the value to False

Related Links:
KnowledgeBase 595FQJPI: Can I Use Visual Studio 2010 with TestStand and Call .NET Framework 4.0 Code Modules?

山有枢 2024-10-10 02:08:31

简单地说,您只需将错误程序集选择到解决方案面板/参考中即可。然后,按 Alt-Enter(属性),找到“Embed Interop Type”,如果为 True,则将其值设置为“False”
布格斯!

Simply, you just choose the error assembly into Solution Panel/References. Then, press Alt-Enter (Properties), find "Embed Interop Type" and set its value to "False" if it True
Brgs !

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