我正在尝试向ImageMagickNet类添加一个自定义函数。它应该使用ImageMagick.NET项目中的IsSimilarImage magick方法,但是我不知道是否必须通过Magick++路由这个方法,因为.NET端可用的任何功能都源自Magick++。
发布于 2015-05-19 12:25:27
这是相当古老的,但因为它是没有回答的,这是。
请注意,我没有研究过ImageMagick库,因此以下代码中的任何实现细节都只是一个示例。用正确的实现替换垃圾。假设它导出的是有效的.NET对象,它的工作方式如下:
' Put your extension methods or properties in a clearly labeled module file, on its own within your project
Module ImageMagickNetExtensions
' Define an extension method by using the ExtensionAttribute, and make the first argument
' for the method the type that you wish to extend. This will serve as a reference to the extended
' instance, so that you can reference other methods and properties within your extension code.
<Extension()> _
Public Function SomeExtensionFunction(ByVal imn As ImageMagickNet, ByVal filename As String) As Boolean
Return imn.IsSimilarImage(filename)
End Function
End Module
Class SomeClass
' To use your extension method within your project containing the extension module, simply
' call it on any valid instance of the type you have extended. The compiler will call your code
' whenever it sees reference to it, passing a reference to your extended instance.
Private imn As New ImageMagickNet
Private Sub DoSomething()
If imn.SomeExtensionFunction("c:\someimage.jpg") Then
...
End If
End Sub
End Classhttps://stackoverflow.com/questions/2232306
复制相似问题