2010-02-09 12 views
23

Estoy tratando de agregar una función personalizada para clasificar ImageMagickNet. Debería usar el método IsSimilarImage magick del proyecto ImageMagick.NET, pero estoy confundido en cuanto a si tengo que enrutar este método a través de Magick ++, ya que cualquier funcionalidad disponible para el lado .NET se origina en Magick ++.Extendiendo ImageMagickNet

Respuesta

2

Esto es bastante viejo, pero como no tiene respuesta, aquí va.

Tenga en cuenta que no he examinado las bibliotecas de ImageMagick, por lo que cualquier detalle de implementación en el siguiente código es estrictamente un ejemplo. Reemplazar basura con la implementación correcta. Suponiendo que está exportando objetos .NET válidos, así es como funcionaría:

' 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