TurboMagic 92 Posted July 12, 2022 Hello, I'm currently playing with Kastri's Camera demo, which is based on the Android Camera2 API. Now I'm struggeling with getting capabilities of the camera used and later on I even need to change some settings. After finding out how the basic structure of this demo works I added this method to get some capabilities as string to get started: function TPlatformCamera.GetCapabilities: string; var LCharacteristics : JCameraCharacteristics; Orientation : Integer; Obj : JObject; IntArray : TJavaObjectArray<integer>; i : Integer; begin LCharacteristics := FCameraManager.getCameraCharacteristics(FSelectedCamera); Obj := LCharacteristics.get(TJCameraCharacteristics.JavaClass.LENS_FACING); Orientation := TJInteger.Wrap(Obj).intValue; if (Orientation = TJCameraMetadata.JavaClass.LENS_FACING_FRONT) then Result := 'Camera: front' + sLineBreak else Result := 'Camera: back' + sLineBreak; Obj := LCharacteristics.get(TJCameraCharacteristics.JavaClass.CONTROL_AE_AVAILABLE_ANTIBANDING_MODES); end; FSelectedCamera is a JString and assigned where the component goes through the list of available cameras and selects the desired one. Reading which camera is selected already seems to work, since this just returns a simple integer value. But how to deal with CONTROL_AE_AVAILABLE_ANTIBANDING_MODES, which, according to the API docs API docs returns int[], which is some kind of array? How to access this from Delphi? And even more: CONTROL_AE_COMPENSATION_RANGE, which returns an array (with two elements) of Range<Integer>? And CONTROL_AE_COMPENSATION_STEP which returns a Rational? I haven't found the definition of this Rational type in Androidapi.JNI.JavaTypes or Androidapi.JNIBridge. Share this post Link to post
TurboMagic 92 Posted July 12, 2022 (edited) Meanwhile I learned that there's no support in the Java bridge yet to get access to these data types, which means one must implement some things on "the Java side". Edited July 12, 2022 by TurboMagic Share this post Link to post
Dave Nottage 575 Posted Wednesday at 08:14 PM I came across this post whilst looking for something else, and... On 7/13/2022 at 12:04 AM, TurboMagic said: Meanwhile I learned that there's no support in the Java bridge yet to get access to these data types, which means one must implement some things on "the Java side". ..actually, there is a way of achieving this using Delphi code. The following will convert the JObject reference (Obj in your case) to an integer array: function JObjectToIntArray(const AObject: JObject): TArray<Integer>; var LJNIArray: JNIArray; LJNIEnv: PJNIEnv; begin LJNIArray := TJNIResolver.JavaInstanceToID(AObject); SetLength(Result, TJNIResolver.GetArrayLength(LJNIArray)); if Length(Result) > 0 then begin LJNIEnv := TJNIResolver.GetJNIEnv; LJNIEnv^.GetIntArrayRegion(LJNIEnv, LJNIArray, 0, Length(Result), PJNIInt(Result)); TJNIResolver.ExceptionCheck; end; end; On 7/12/2022 at 7:34 PM, TurboMagic said: And even more: CONTROL_AE_COMPENSATION_RANGE, which returns an array (with two elements) of Range<Integer>? For Range<Integer>: var LRange: JRange; LLower, LUpper: Integer; LRange := TJRange.Wrap(Obj); LLower := TJInteger.Wrap(LRange.getLower).intValue; LUpper := TJInteger.Wrap(LRange.getUpper).intValue; On 7/12/2022 at 7:34 PM, TurboMagic said: And CONTROL_AE_COMPENSATION_STEP which returns a Rational? I haven't found the definition of this Rational type in Androidapi.JNI.JavaTypes or Androidapi.JNIBridge. It's in Androidapi.JNI.Util. To convert the JObject reference, simply Wrap it: var LRational: JRational; LRational := TJRational.Wrap(Obj); 1 Share this post Link to post