[英]C# subclass of this base class?
所以Xamarin.ios,GPUImage的這個組件最初是在目標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
子類應該獲得三個圖像中最亮的像素並從中返回一個圖像。 相反,它只返回第一個圖像,因為字符串沒有在子類中注冊。
所以,我問,這應該是什么樣的子類,它接受的NSString
應該去哪里? 我以前沒有碰過這樣的課。 謝謝
更新:
我現在正在使用並重新調整此處找到的方法,但是對於已處理的顏色數組所做的所有調用大約需要四到五分鍾,這最多需要幾秒鍾,所以我仍然會在某個時候嘗試解決這個問題。 。
您的自定義類“GPUImageThreeInputFilter”派生自基類GPUImageTwoInputFilter
這是你的意圖嗎? 也許您應該以不同的方式命名自定義類,並使其繼承自GPUImageThreeInputFilter類。
它似乎工作。 我剛剛嘗試了一個示例項目,結果如下:
ImageProcess.cs :
public class ImageProcess : GPUImageThreeInputFilter
{
public static new NSString ThreeInputTextureVertexShaderString
=> new NSString("My string");
}
輸出:
var process = new ImageProcess();
Console.WriteLine(process);
你能告訴我你的預期結果是什么嗎? 也許你的代碼中有一些你創建ImageProcess對象?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.