Question

Je suis en train d'ajouter une fonction personnalisée à ImageMagickNet de classe. Il faut utiliser la méthode IsSimilarImage magick du projet ImageMagick.NET mais je suis confus quant à savoir si je dois acheminer cette méthode par la Magick ++, comme toutes les fonctionnalités disponibles sur le côté .NET son origine dans la Magick ++.

Pas de solution correcte

Autres conseils

Ceci est assez vieux, mais comme il est sans réponse, va ici.

S'il vous plaît noter que je ne l'ai pas regardé les bibliothèques ImageMagick, afin de détails de mise en œuvre dans le code ci-dessous est strictement un exemple. Remplacer les déchets avec la mise en œuvre correcte. En supposant qu'il exporte des objets .NET valides, voici comment cela fonctionnerait:

' 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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top