gpt4 book ai didi

.net - 扩展 ImageMagickNet

转载 作者:行者123 更新时间:2023-12-02 17:23:20 25 4
gpt4 key购买 nike

我正在尝试向 ImageMagickNet 类添加自定义函数。它应该使用 ImageMagick.NET 项目中的 IsSimilarImage magick 方法,但我很困惑是否必须通过 Magick++ 路由此方法,因为 .NET 端可用的任何功能都源自魔法++。

最佳答案

这已经很老了,但由于没有答案,所以就在这里。

请注意,我没有查看过 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

关于.net - 扩展 ImageMagickNet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2232306/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com