1

我在 C++Builder 10.2 Tokyo 中有一个仅针对 Android 的 FMX 项目。我正在尝试使用Camera2 API。我使用Java2Pas工具创建了我需要的 Delphi 接口和类,将它们组合成一个 Pascal 文件,我已将其添加到我的 C++ 项目中。

此 pascal 文件的部分内容如下所示:

  JTextureView_SurfaceTextureListenerClass = interface(JObjectClass)
    ['{106DB13E-C1B4-4898-B906-0143D97C0075}']
    function onSurfaceTextureDestroyed(JSurfaceTextureparam0 : JSurfaceTexture) : boolean; cdecl;// (Landroid/graphics/SurfaceTexture;)Z A: $401
    procedure onSurfaceTextureAvailable(JSurfaceTextureparam0 : JSurfaceTexture; Integerparam1 : Integer; Integerparam2 : Integer) ; cdecl;// (Landroid/graphics/SurfaceTexture;II)V A: $401
    procedure onSurfaceTextureSizeChanged(JSurfaceTextureparam0 : JSurfaceTexture; Integerparam1 : Integer; Integerparam2 : Integer) ; cdecl;// (Landroid/graphics/SurfaceTexture;II)V A: $401
    procedure onSurfaceTextureUpdated(JSurfaceTextureparam0 : JSurfaceTexture) ; cdecl;// (Landroid/graphics/SurfaceTexture;)V A: $401
  end;

  [JavaSignature('android/view/TextureView_SurfaceTextureListener')]
  JTextureView_SurfaceTextureListener = interface(JObject)
    ['{58A7FBD1-27B9-44AC-B013-F077E1BF5975}']
    function onSurfaceTextureDestroyed(JSurfaceTextureparam0 : JSurfaceTexture) : boolean; cdecl;// (Landroid/graphics/SurfaceTexture;)Z A: $401
    procedure onSurfaceTextureAvailable(JSurfaceTextureparam0 : JSurfaceTexture; Integerparam1 : Integer; Integerparam2 : Integer) ; cdecl;// (Landroid/graphics/SurfaceTexture;II)V A: $401
    procedure onSurfaceTextureSizeChanged(JSurfaceTextureparam0 : JSurfaceTexture; Integerparam1 : Integer; Integerparam2 : Integer) ; cdecl;// (Landroid/graphics/SurfaceTexture;II)V A: $401
    procedure onSurfaceTextureUpdated(JSurfaceTextureparam0 : JSurfaceTexture) ; cdecl;// (Landroid/graphics/SurfaceTexture;)V A: $401
  end;

  TJTextureView_SurfaceTextureListener = class(TJavaGenericImport<JTextureView_SurfaceTextureListenerClass, JTextureView_SurfaceTextureListener>)
  end;

TJTextureView_SurfaceTextureListener接口需要用作回调对象,因此我向其添加了一些事件处理程序并将其更改为如下所示:

  TOnSurfaceTextureDestroyed = function(aSurface: JSurfaceTexture): Boolean of object;
  TOnSurfaceTextureUpdated = procedure(aSurface: JSurfaceTexture) of object;
  TOnSurfaceTextureSize = procedure(aSurface: JSurfaceTexture; aWidth:Integer; aHeight: Integer)  of object;

  TJTextureView_SurfaceTextureListener = class(TJavaGenericImport<JTextureView_SurfaceTextureListenerClass, JTextureView_SurfaceTextureListener>)
  protected
    FOnTextureDestroyed: TOnSurfaceTextureDestroyed;
    FOnTextureUpdated: TOnSurfaceTextureUpdated;
    FOnTextureAvailable: TOnSurfaceTextureSize;
    FOnTextureSizeChanged: TOnSurfaceTextureSize;

  public
    function onSurfaceTextureDestroyed(aSurface : JSurfaceTexture) : boolean; cdecl;
    procedure onSurfaceTextureAvailable(aSurface : JSurfaceTexture; aWidth : Integer; aHeight : Integer) ; cdecl;
    procedure onSurfaceTextureSizeChanged(aSurface : JSurfaceTexture; aWidth : Integer; aHeight : Integer) ; cdecl;
    procedure onSurfaceTextureUpdated(aSurface : JSurfaceTexture) ; cdecl;

    property OnTextureDestroyed: TOnSurfaceTextureDestroyed read FOnTextureDestroyed write FOnTextureDestroyed;
    property OnTextureUpdated: TOnSurfaceTextureUpdated read FOnTextureUpdated write FOnTextureUpdated;
    property OnTextureAvailable: TOnSurfaceTextureSize read FOnTextureAvailable write FOnTextureAvailable;
    property OnTextureSizeChanged: TOnSurfaceTextureSize read FOnTextureSizeChanged write FOnTextureSizeChanged;
  end;

implementation

{ TJTextureView_SurfaceTextureListener }

procedure TJTextureView_SurfaceTextureListener.onSurfaceTextureAvailable(aSurface: JSurfaceTexture; aWidth, aHeight: Integer);
begin
  if Assigned(FOnTextureAvailable) then
    FOnTextureAvailable(aSurface, aWidth, aHeight);
end;

function TJTextureView_SurfaceTextureListener.onSurfaceTextureDestroyed(aSurface: JSurfaceTexture): boolean;
begin
  if Assigned(FOnTextureDestroyed) then
    Result := FOnTextureDestroyed(aSurface)
  else
    Result := False;
end;

procedure TJTextureView_SurfaceTextureListener.onSurfaceTextureSizeChanged(aSurface: JSurfaceTexture; aWidth, aHeight: Integer);
begin
  if Assigned(FOnTextureSizeChanged) then
    FOnTextureSizeChanged(aSurface, aWidth, aHeight);
end;

procedure TJTextureView_SurfaceTextureListener.onSurfaceTextureUpdated(aSurface: JSurfaceTexture);
begin
  if Assigned(FOnTextureUpdated) then
    FOnTextureUpdated(aSurface);
end;

IDE 创建的头文件如下所示:

__interface JTextureView_SurfaceTextureListenerClass;
typedef System::DelphiInterface<JTextureView_SurfaceTextureListenerClass> _di_JTextureView_SurfaceTextureListenerClass;
__interface JTextureView_SurfaceTextureListener;
typedef System::DelphiInterface<JTextureView_SurfaceTextureListener> _di_JTextureView_SurfaceTextureListener;
class DELPHICLASS TJTextureView_SurfaceTextureListener;

__interface  INTERFACE_UUID("{106DB13E-C1B4-4898-B906-0143D97C0075}") JTextureView_SurfaceTextureListenerClass  : public Androidapi::Jni::Javatypes::JObjectClass 
{
    virtual bool __cdecl onSurfaceTextureDestroyed(Androidapi::Jni::Graphicscontentviewtext::_di_JSurfaceTexture JSurfaceTextureparam0) = 0 ;
    virtual void __cdecl onSurfaceTextureAvailable(Androidapi::Jni::Graphicscontentviewtext::_di_JSurfaceTexture JSurfaceTextureparam0, int Integerparam1, int Integerparam2) = 0 ;
    virtual void __cdecl onSurfaceTextureSizeChanged(Androidapi::Jni::Graphicscontentviewtext::_di_JSurfaceTexture JSurfaceTextureparam0, int Integerparam1, int Integerparam2) = 0 ;
    virtual void __cdecl onSurfaceTextureUpdated(Androidapi::Jni::Graphicscontentviewtext::_di_JSurfaceTexture JSurfaceTextureparam0) = 0 ;
};

__interface  INTERFACE_UUID("{58A7FBD1-27B9-44AC-B013-F077E1BF5975}") JTextureView_SurfaceTextureListener  : public Androidapi::Jni::Javatypes::JObject 
{
    virtual bool __cdecl onSurfaceTextureDestroyed(Androidapi::Jni::Graphicscontentviewtext::_di_JSurfaceTexture JSurfaceTextureparam0) = 0 ;
    virtual void __cdecl onSurfaceTextureAvailable(Androidapi::Jni::Graphicscontentviewtext::_di_JSurfaceTexture JSurfaceTextureparam0, int Integerparam1, int Integerparam2) = 0 ;
    virtual void __cdecl onSurfaceTextureSizeChanged(Androidapi::Jni::Graphicscontentviewtext::_di_JSurfaceTexture JSurfaceTextureparam0, int Integerparam1, int Integerparam2) = 0 ;
    virtual void __cdecl onSurfaceTextureUpdated(Androidapi::Jni::Graphicscontentviewtext::_di_JSurfaceTexture JSurfaceTextureparam0) = 0 ;
};

typedef bool __fastcall (__closure *TOnSurfaceTextureDestroyed)(Androidapi::Jni::Graphicscontentviewtext::_di_JSurfaceTexture aSurface);
typedef void __fastcall (__closure *TOnSurfaceTextureUpdated)(Androidapi::Jni::Graphicscontentviewtext::_di_JSurfaceTexture aSurface);
typedef void __fastcall (__closure *TOnSurfaceTextureSize)(Androidapi::Jni::Graphicscontentviewtext::_di_JSurfaceTexture aSurface, int aWidth, int aHeight);

class PASCALIMPLEMENTATION TJTextureView_SurfaceTextureListener : public Androidapi::Jnibridge::TJavaGenericImport__2<_di_JTextureView_SurfaceTextureListenerClass,_di_JTextureView_SurfaceTextureListener> 
{
    typedef Androidapi::Jnibridge::TJavaGenericImport__2<_di_JTextureView_SurfaceTextureListenerClass,_di_JTextureView_SurfaceTextureListener>  inherited;

protected:
    TOnSurfaceTextureDestroyed FOnTextureDestroyed;
    TOnSurfaceTextureUpdated FOnTextureUpdated;
    TOnSurfaceTextureSize FOnTextureAvailable;
    TOnSurfaceTextureSize FOnTextureSizeChanged;

public:
    bool __cdecl onSurfaceTextureDestroyed(Androidapi::Jni::Graphicscontentviewtext::_di_JSurfaceTexture aSurface);
    void __cdecl onSurfaceTextureAvailable(Androidapi::Jni::Graphicscontentviewtext::_di_JSurfaceTexture aSurface, int aWidth, int aHeight);
    void __cdecl onSurfaceTextureSizeChanged(Androidapi::Jni::Graphicscontentviewtext::_di_JSurfaceTexture aSurface, int aWidth, int aHeight);
    void __cdecl onSurfaceTextureUpdated(Androidapi::Jni::Graphicscontentviewtext::_di_JSurfaceTexture aSurface);
    __property TOnSurfaceTextureDestroyed OnTextureDestroyed = {read=FOnTextureDestroyed, write=FOnTextureDestroyed};
    __property TOnSurfaceTextureUpdated OnTextureUpdated = {read=FOnTextureUpdated, write=FOnTextureUpdated};
    __property TOnSurfaceTextureSize OnTextureAvailable = {read=FOnTextureAvailable, write=FOnTextureAvailable};
    __property TOnSurfaceTextureSize OnTextureSizeChanged = {read=FOnTextureSizeChanged, write=FOnTextureSizeChanged};
public:
    /* TObject.Create */ inline __fastcall TJTextureView_SurfaceTextureListener(void) : Androidapi::Jnibridge::TJavaGenericImport__2<_di_JTextureView_SurfaceTextureListenerClass,_di_JTextureView_SurfaceTextureListener> () { }
    /* TObject.Destroy */ inline __fastcall virtual ~TJTextureView_SurfaceTextureListener(void) { }

};

在我的 C++ 代码中,我试图像这样使用它:

_di_JTextureView_SurfaceTextureListener = TJTextureView_SurfaceTextureListener::JavaClass->init();
SurfaceTextureListener->OnTextureAvailable = SetupCamera;

但是编译器给了我一个错误:

在“Androidcamera2::JTextureView_SurfaceTextureListener”中没有名为“OnTextureAvailable”的成员

谁能告诉我我在这里做错了什么?

4

1 回答 1

0

您收到错误消息是因为JTextureView_SurfaceTextureListener接口没有该OnTextureAvailable属性。

这里的想法是JTextureView_SurfaceTextureListener接口回调,你应该JTextureView_SurfaceTextureListener在你自己的对象中实现接口。然后,在您的onSurfaceTextureAvailable实现中,您调用 SetupCamera。

请注意,您必须调用TextureView.setSurfaceTextureListener并传递您的实例的JTextureView_SurfaceTextureListener实例才能注册您的侦听器。

于 2017-11-30T16:55:13.373 回答