2017-08-30 32 views
3

所以有Xamarin.ios,GPUImage,這是最初在客觀的c,現在使用綁定工作在C#中的這個組件。這個基類的C#子類?

我似乎無法得到它的一個類的工作子類,GPUImageThreeInputFilter,它應該接受一個字符串,然後被處理爲glsl。 這是類的樣子:

using Foundation; 
using System; 
using System.ComponentModel; 
using System.Runtime.CompilerServices; 

namespace GPUImage.Filters 
{ 
    [Register ("GPUImageThreeInputFilter", true)] 
    public class GPUImageThreeInputFilter : GPUImageTwoInputFilter 
    { 
     // 
     // Static Fields 
     // 
     [CompilerGenerated] 
     private static readonly IntPtr class_ptr; 

     [CompilerGenerated] 
     private static NSString _ThreeInputTextureVertexShaderString; 

     // 
     // Static Properties 
     // 
     [Field ("kGPUImageThreeInputTextureVertexShaderString", "__Internal")] 
     public static NSString ThreeInputTextureVertexShaderString { 
      get; 
     } 

     // 
     // Properties 
     // 
     public override IntPtr ClassHandle { 
      get; 
     } 

     // 
     // Constructors 
     // 
     [Export ("init"), EditorBrowsable (EditorBrowsableState.Advanced), CompilerGenerated] 
     public GPUImageThreeInputFilter(); 

     [EditorBrowsable (EditorBrowsableState.Advanced), CompilerGenerated] 
     protected GPUImageThreeInputFilter (NSObjectFlag t); 

     [EditorBrowsable (EditorBrowsableState.Advanced), CompilerGenerated] 
     protected internal GPUImageThreeInputFilter (IntPtr handle); 

     // 
     // Methods 
     // 
     [Export ("disableThirdFrameCheck"), CompilerGenerated] 
     public virtual void DisableThirdFrameCheck(); 
    } 
} 

我創建的這個子類:

public class ImageProcess : GPUImageThreeInputFilter 
    { 
     public static new NSString ThreeInputTextureVertexShaderString = 
       ((NSString)(" varying highp vec2 textureCoordinate;" + 
       " varying highp vec2 textureCoordinate2;" + 
       " varying highp vec2 textureCoordinate3;" + 
       "" + 
       " uniform sampler2D inputImageTexture;" + 
       " uniform sampler2D inputImageTexture2;" + 
       " uniform sampler2D inputImageTexture3;" + 
       "" + 
       " void main()" + 
       " {" + 
       "   lowp vec4 one = texture2D(inputImageTexture, textureCoordinate);" + 
       "   lowp vec4 two = texture2D(inputImageTexture2, textureCoordinate2);" + 
       "   lowp vec4 three = texture2D(inputImageTexture3, textureCoordinate3);" + 
       "   lowp vec4 out;" + 
       "   float maxone = one.r + one.g + one.b;" + 
       "   float maxtwo = two.r + two.g + two.b;" + 
       "   float maxthree = three.r + three.g + three.b;" + 
       "   if (maxone >= maxtwo && maxone >= maxthree)" + 
       "   {" + 
       "   out.r = one.r;" + 
       "   out.b = one.b;" + 
       "   out.g = one.g;" + 
       "   };" + 
       "   if (maxtwo >= maxone && maxtwo >= maxthree)" + 
       "   {" + 
       "   out.r = two.r;" + 
       "   out.b = two.b;" + 
       "   out.g = two.g;" + 
       "   };" + 
       "   if (maxthree >= maxtwo && maxthree >= maxone)" + 
       "   {" + 
       "   out.r = three.r;" + 
       "   out.b = three.b;" + 
       "   out.g = three.g;" + 
       "   };" + 
       "   out.a = 1.0;" + 
       "   gl_FragColor = out;" + 
             "  }")); 
    } 

使用子類:

var firstFilter = new ImageProcess(); 

first.AddTarget(firstFilter);  // first, second, and third 
first.ProcessImage();    // are unique GPUImagePicture 
second.AddTarget(firstFilter); // values (pictures) defined 
second.ProcessImage();   // somewhere else. 
third.AddTarget(firstFilter); 
third.ProcessImage(); 
firstFilter.UseNextFrameForImageCapture(); 
firstFilter.AddTarget(output); // outputs the end result to 
            // the screen 

的子類應該獲得三個圖像中最亮的像素並返回一個圖像fr那個。相反,它只是返回第一個圖像,因爲該字符串沒有在子類中註冊。

所以,我問,這個樣子的適當的子類應該是什麼樣的,它接受的NSString應該在哪裏去?之前我沒有碰過類似這樣的課。由於

更新:

我使用和再利用的方法找到here現在,但是,對於一個處理色陣列所做的所有調用花費大約四到五分鐘在那裏,這將需要幾秒鐘大多數,所以我仍然會嘗試在某個時候解決這個問題。

回答

0

您的自定義類「GPUImageThreeInputFilter」從基類GPUImageTwoInputFilter

衍生 那是你的意圖? 也許你應該以不同的方式命名你的自定義類並使它從GPUImageThreeInputFilter類繼承。

+0

「GPUImageThreeInputFilter」繼承自「GPUImageTwoInputFilter」,但自定義類繼承自「GPUImageThreeInputFilter」。我已更新該帖子以澄清此問題。 –

0

它似乎工作。我只是想在一個示例項目,現在這裏是結果:

ImageProcess.cs

public class ImageProcess : GPUImageThreeInputFilter 
{ 
    public static new NSString ThreeInputTextureVertexShaderString 
     => new NSString("My string"); 
} 

輸出:

var process = new ImageProcess(); 
Console.WriteLine(process); 

enter image description here

莫非你告訴我你的預期結果是什麼?也許你的代碼在你創建ImageProcess對象的位置?

+0

當然,用這些東西更新了這篇文章。 –