扩展 ImageMagickNet

发布于 2024-08-21 00:38:35 字数 141 浏览 7 评论 0原文

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

I’m trying to add a custom function to class ImageMagickNet. It should use the IsSimilarImage magick method from the ImageMagick.NET project but I’m confused as to whether I have to route this method through the Magick++, as any functionality available to the .NET side originates in the Magick++.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故人爱我别走 2024-08-28 00:38:35

这已经很老了,但由于尚未得到答复,所以就到这里。

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

This is pretty old but as is it unanswered, here goes.

Please note that I have not looked at the ImageMagick libraries, so any implementation details in the below code is strictly an example. Replace rubbish with correct implementation. Assuming it is exporting valid .NET objects, this is how it would work:

' 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文