ImageMagickNet sınıfına özel bir işlev eklemeye çalışıyorum. ImageMagick.NET projesinden IsSimilarImage magick
yöntemini kullanmalıdır, ancak .NET yönteminde kullanılabilen herhangi bir işlev Magick ++ 'dan kaynaklandığı için, bu yöntemi Magick ++ yoluyla yönlendirmem gerekip gerekmediğime dair kafam karıştı.ImageMagickNet'i genişletme
23
A
cevap
2
Bu oldukça eski ama cevapsız olduğu gibi, işte burada.
Lütfen ImageMagick kitaplıklarına bakmadığımı unutmayın, bu nedenle aşağıdaki koddaki uygulama ayrıntıları kesinlikle bir örnektir. Çöpleri doğru uygulayarak değiştirin. Geçerli .NET nesnelerini dışa aktardığını varsayarsak, şu şekilde çalışır:
' 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