2010-11-18 3 views
23

私は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"); 
} 

この小さなテストを実行しようとすると、私はこのエラーを取得:

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

そして、この:

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

私は推測しています最初のエラーのために2番目のエラーが発生しています。

これを修正する方法の提案はありますか?

+0

私は、CommonDialogClassが.NET 3.5で動作し、発生している問題がそれ以降のバージョンで導入されていることがわかりました。 –

答えて

26

2番目のエラーは最初のエラーが原因です。 Embed Interop Types機能は、クラスではなく埋め込みインターフェースのみをサポートします。ただFalseにWIA参照でそのオプションを設定し、相互運用ライブラリをデプロイ以外に、あなたはまた、このようにそれを修正することができます:

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

直感しかし新しいオペレータが許可されているとCOMインターフェイスを作成します。 CommonDialogはWinforms CommonDialogクラスであいまいであるため、名前空間の接頭辞を付ける必要があります。

+1

Unreal!どのような操作でもインテリセンスを得ることはできませんが、実際には期待通りの性能を発揮するという点で、「ダイナミック」クラスのように動作します。ありがとう、友達! –

9

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

デフォルト値は、新しいプロジェクトで参照TestStandのAPI相互運用機能アセンブリの埋め込み相互運用機能タイププロパティに対して真であるため、このエラーが発生します。

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:このエラーを解決するには、次の手順を実行して、Falseに埋め込み相互運用型プロパティの値を変更し、私はTestStandのとコールの.NET Framework 4.0のコードでのVisual Studio 2010を使用することができますモジュール?

4

単にエラーパネルをソリューションパネル/参照に設定するだけです。次に、Alt-Enter(プロパティ)を押し、「Embed Interop Type」を見つけてTrueの場合はその値を「False」に設定します。 Brgs!

関連する問題