簡體   English   中英

編輯文件元數據-代碼在VB中很好,但在C#中不是

[英]Edit file metadata - Code is fine in VB but not C#

這是當前使用的VB.NET方法,效果很好。

Private Sub editMetadata(ByRef bmp1 As Bitmap, ByVal intTitleId As Integer, ByVal strTitle As String)

        Dim ci As System.Reflection.ConstructorInfo = _
                       GetType(PropertyItem).GetConstructor(BindingFlags.NonPublic Or _
                       BindingFlags.Instance Or BindingFlags.[Public], Nothing, New Type() {}, Nothing)

        Dim outPropertyItem As PropertyItem = DirectCast(ci.Invoke(Nothing), PropertyItem)

        outPropertyItem.Id = intTitleId

        ' Type=1 means Array of Bytes. 
        outPropertyItem.Type = 1
        outPropertyItem.Len = strTitle.Length

        outPropertyItem.Value = Encoding.Unicode.GetBytes(strTitle)

        bmp1.SetPropertyItem(outPropertyItem)

End Sub


現在在C#中,使用此方法的第一行遇到了一個障礙。

System.Reflection.ConstructorInfo ci = 
      GetType(PropertyItem).GetConstructor( BindingFlags.NonPublic ||
      BindingFlags.Instance || BindingFlags.[Public], null, new Type() {}, null);


將語法從VB轉換為C#(我很熟悉)后,這一節仍然有6個錯誤。

錯誤



因此,該問題可以通過幾種方式解決...

上面顯示的代碼正確的C#語法是什么。

要么..

如何在C#中正確編輯文件元數據。

感謝您的任何幫助!

System.Reflection.ConstructorInfo ci = 
      typeof(PropertyItem).GetConstructor( BindingFlags.NonPublic |
      BindingFlags.Instance | BindingFlags.Public, null, new Type[] {}, null);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM