类不能被嵌入。使用适用的接口而不是 [英] Class cannot be embedded. Use the applicable interface instead

查看:524
本文介绍了类不能被嵌入。使用适用的接口而不是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用WIA捕捉弗朗扫描仪到Windows窗体的图像。下面是我使用的代码:

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:

互操作型'WIA.CommonDialogClass'
不能嵌入。 。使用适用
接口,而不是

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

和这样的:

WIA.CommonDialogClass不
包含
'ShowAcquireImage'没有扩展名
法ShowAcquireImage接受的
第一个参数定义类型
'WIA.CommonDialogClass可以发现
(是否缺少using指令或
程序集引用?

'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?

推荐答案

第二错误是由第一种造成的,嵌入互操作类型功能只支持嵌入接口,而不是类。除了只设置了在WIA参考False选项和部署互操作库,你也可以修复它是这样的:

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();

直观,但创造COM与新运营商是允许的。您需要前缀的名称空间的名字,因为的的CommonDialog 的是模糊的的WinForms的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.

这篇关于类不能被嵌入。使用适用的接口而不是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆