我想自定义函数添加到类ImageMagickNet。它应该使用IsSimilarImage magick方法从ImageMagick.NET项目,但我很困惑,我是否有借道Magick ++这种方法,可用以.NET方面的任何功能的Magick ++。

起源

没有正确的解决方案

其他提示

这是很老,但因为是无人接听,在这里不用。

请注意,我没有看过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 Class
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top