[英]Extending an interface with another interface
今天是個好日子,
我對接口及其相互之間如何擴展/繼承有疑問。 這個問題與GPU編程無關。
問題:
我有兩個接口:GPUImageView和GPUImageInput。
定義了GPUImageView: interface GPUImageView : GPUImageInput { /*some code*/ }
我有一個函數: void AddTarget(GPUImageInput newTarget) {/*some code*/}
當我將GPUImageView的一個實例傳遞給AddTarget時,出現一個錯誤,它無法將GPUImageView轉換為GPUImageInput。
附加信息:
我試圖用btouch綁定Monotouch中的GPUImage庫。 我嘗試將他們的示例之一(SimplePhotoFilter)移植為測試。
這導致
這是APIDefinitions.cs中的代碼
namespace GPUImage
{
[BaseType (typeof(UIView))]
interface GPUImageView : GPUImageInput{
[Export ("initWithFrame:")]
IntPtr Constructor(RectangleF frame);
[Export ("autoresizingMask")]
UIViewAutoresizing AutoResizingMask { get; set;}
[Export ("addSubView")]
void AddSubView(UIView view);
}
[BaseType (typeof(NSObject))]
[Model]
interface AVCaptureVideoDataOutputSampleBufferDelegate{
}
[BaseType (typeof(NSObject))]
[Model]
interface AVCaptureAudioDataOutputSampleBufferDelegate{
}
[BaseType (typeof(GPUImageOutput))]
interface GPUImageVideoCamera : AVCaptureVideoDataOutputSampleBufferDelegate, AVCaptureAudioDataOutputSampleBufferDelegate{
}
[BaseType (typeof(GPUImageVideoCamera))]
interface GPUImageStillCamera{
[Export ("outputImageOrientation")]
UIInterfaceOrientation OutputImageOrientation { get; set;}
[Export ("startCameraCapture")]
void StartCameraCapture();
}
[BaseType (typeof(GPUImageSobelEdgeDetectionFilter))]
interface GPUImageSketchFilter{
[Export ("prepareForImageCapture")]
void PrepareForImageCapture();
}
[BaseType (typeof(GPUImageTwoPassFilter))]
interface GPUImageSobelEdgeDetectionFilter {
[Export ("texelWidth")]
float TexelWidth{ get; set;}
[Export ("texelHeight")]
float TexelHeight{ get; set;}
}
[BaseType (typeof(GPUImageFilter))]
interface GPUImageTwoPassFilter {
}
[BaseType (typeof(GPUImageOutput))]
interface GPUImageFilter : GPUImageInput{
}
[BaseType (typeof(NSObject))]
[Model]
interface GPUImageInput{
}
[BaseType (typeof(NSObject))]
interface GPUImageOutput{
[Export ("addTarget")]
void AddTarget(GPUImageInput newTarget);
}
}
這是viewController中的代碼:
GPUImage.GPUImageStillCamera stillCamera = new GPUImage.GPUImageStillCamera ();
stillCamera.OutputImageOrientation = UIInterfaceOrientation.Portrait;
GPUImage.GPUImageFilter filter = (GPUImage.GPUImageSketchFilter)new GPUImage.GPUImageSketchFilter ();
((GPUImage.GPUImageSketchFilter)filter).TexelHeight = 1.0f / 1024.0f;
((GPUImage.GPUImageSketchFilter)filter).TexelWidth = 1.0f / 768.0f;
((GPUImage.GPUImageSketchFilter)filter).PrepareForImageCapture ();
stillCamera.AddTarget (filter);
GPUImage.GPUImageView filterView = (GPUImage.GPUImageView)this.View;
filter.AddTarget (filterView);
這些是我得到的錯誤消息:ImageProcessingLabViewController.cs(37,37):錯誤CS1503:參數#1' cannot convert
GPUImage.GPUImageOutput表達式#1' cannot convert
為類型GPUImage.GPUImageInput(CS1503)(ImageProcessingLab)
ImageProcessingLabViewController.cs(32,32):錯誤CS1503:參數#1' cannot convert
GPUImage.GPUImageView表達式#1' cannot convert
為類型GPUImage.GPUImageInput(CS1503)(ImageProcessingLab)
但正如您所看到的,GPUImageFilter繼承/實現/擴展了GPUImageInput,這應該允許我使用/廣播GPUImageSketchFilter,GPUImageOutput和GPUImageView作為GPUImageInput。
澄清:當我嘗試調用需要GPUImageInput的AddTarget時,發生錯誤。 我給它一個GPUImageFilter,它繼承自GPUImageOutput並實現了GPUImageInput。 GPUImageFilter應該可轉換為GPUImageInput,但會導致錯誤。
感謝您提供任何答案。 我想念什么嗎? 謝謝!
我不熟悉該特定框架,但是,實現的硬件選項有限。
如果該庫對圖像使用GPGPU(例如CUDA)緩沖區,則將沒有針對輸入和輸出圖像的單獨定義(也許對於基於紋理內存的快速訪問只讀圖像可能會有單獨的定義)。
如果該庫使用標准圖形管線,則可以將圖像存儲在用作管線輸入的紋理中,或存儲在用作管線輸出的PBuffer中-兩個單獨的物理(或邏輯?)取決於具體的硬件實現)位置。
要從一種內存類型轉換為另一種類型轉換是不夠的,您需要讀取緩沖區並將其寫入不同的分配位置。
框架的實現可能對兩個都使用相同的基類,但是,實現可能不兼容。
您所擁有的沒有可編譯的C#代碼。 這是Obj-C綁定定義。 然后,btouch命令行實用程序會生成實際的C#代碼,並編譯到您可以引用的庫中。 在您的示例中,已編譯程序集中的類定義為
public class GPUImageView : UIView
{
}
和
public class GPUImageOutput : NSObject
{
}
它們實際上都不繼承自GPUImageInput,它們都不是真正的接口。 您可以閱讀本指南以獲取更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.