سؤال

أحاول إضافة وظيفة مخصصة إلى فئة ImageMagicknet. يجب أن تستخدم IsSimilarImage magick الطريقة من مشروع ImageMagick.net ولكني مرتبك فيما إذا كان علي توجيه هذه الطريقة من خلال Magick ++، حيث أن أي وظائف متوفرة ل Side .NET Side ينشأ في Magick ++.

لا يوجد حل صحيح

نصائح أخرى

هذا قديم جدا ولكن كما هو من غير المدعومين، هنا يذهب.

يرجى ملاحظة أنني لم تنظر إلى مكتبات 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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top