我正在尝试向 ImageMagickNet 类添加自定义函数。它应该使用IsSimilarImage magick
ImageMagick.NET 项目中的方法,但我对是否必须通过 Magick++ 路由此方法感到困惑,因为 .NET 端可用的任何功能都源自 Magick++。
问问题
1101 次
1 回答
2
这已经很老了,但是没有答案,就这样吧。
请注意,我没有查看 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
于 2015-05-19T04:25:27.063 回答