因此,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
应该去哪里?我以前没有经历过这样的课程。谢谢
更新:
我现在正在使用并重新调整找到here的方法,但是为处理过的颜色数组调用的所有调用大约需要四到五分钟,这最多需要几秒钟,所以我仍会尝试在某个时候解决这个问题。
答案 0 :(得分:0)
您的自定义类" GPUImageThreeInputFilter"是派生的 来自基类GPUImageTwoInputFilter
这是你的意图吗? 也许您应该以不同的方式命名自定义类,并使其继承自GPUImageThreeInputFilter类。
答案 1 :(得分:0)
似乎有效。我刚刚尝试了一个示例项目,结果如下:
<强> ImageProcess.cs 强>:
public class ImageProcess : GPUImageThreeInputFilter
{
public static new NSString ThreeInputTextureVertexShaderString
=> new NSString("My string");
}
<强>输出:强>
var process = new ImageProcess();
Console.WriteLine(process);
你能告诉我你的预期结果是什么吗?也许你的代码中有一些你创建ImageProcess对象?