繁体   English   中英

这个基类的C#子类?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM