Подтвердить что ты не робот

Расширение ImageMagickNet

Я пытаюсь добавить пользовательскую функцию в класс ImageMagickNet. Он должен использовать метод IsSimilarImage magick из проекта ImageMagick.NET, но Im запутался в том, нужно ли мне маршрутизировать этот метод с помощью Magick ++, так как любая функция, доступная стороне .NET, возникает в Magick ++.

4b9b3361

Ответ 1

Это довольно старый, но, как и без ответа, здесь.

Обратите внимание, что я не смотрел библиотеки 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