android camera access from delphi
<p>I'm building a simple application which acts similar to built-in camera application - takes a photo and saves it locally, with some additional aсtions. First I took Firemonkeys' <code>TCameraComponent</code>, placed it to the form and added transfered image from it to <code>TImage</code>. It works OK, I can change resolution, control flash power and so on. The problem is that preview framerate is very low while running at good quality. If I switch camera to 320x240 resolution, it works fast enough, but quality is poor and I have to switch to some higher resolution to take a good photo - loosing time on re-focusing and light adaptation. If I set high resolution (such as 1280x720) for preview, it slows down to about 3-5 fps.</p>

<p>So I need to use some another technique to access camera. App interface must still unchanged during usage, so I can't use <code>TakePhotoFromCameraAction</code>. I'm looking to JNI interfaces. So I need, using JNI calls, access camera and get a preview at some image object at my form. I use the such code to get preview (I'm a bit lack of understanding native android so it may look crazy):</p>

<pre><code>J.Cam := TJCamera.JavaClass.open(0); // J.Cam is JCamera object
J.View := TJView.JavaClass.init( TAndroidHelper.Context ); // JView
J.ViewParams := TJViewGroup_LayoutParams.JavaClass.init(Width, Height); // i got Width and Height from J.Cam.getParameters()
TAndroidHelper.Activity.addContentView( J.View, J.ViewParams );

J.SurfaceView := TJSurfaceView.JavaClass.init( J.View.getContext );
J.LayoutParameters := TJViewGroup_LayoutParams.JavaClass.init(Width, Height);
J.SurfaceView.setLayoutParams( J.LayoutParameters );

J.Cam.setPreviewDisplay( J.SurfaceView.getHolder );
J.Cam.startPreview;
</code></pre>

<p>and it doesn't show anything except black screen. Google developer reference <a href="http://developer.android.com/intl/ru/reference/android/hardware/Camera.html#setPreviewDisplay(android.view.SurfaceHolder)" rel="nofollow">says that</a> "If you are using <code>SurfaceView</code>, you will need to register a <code>SurfaceHolder.Callback</code> with <code>addCallback(SurfaceHolder.Callback)</code> and wait for <code>surfaceCreated(SurfaceHolder)</code> before calling <code>setPreviewDisplay()</code> or starting preview."</p>

<p>So the next step I should create the callback class, extending SurfaceView and implementing SurfaceHolder.Callback. There are many samples can be found like this:</p>

<pre><code>public class TestActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(new MySurfaceView(this));

    }


    public class MySurfaceView extends SurfaceView implements SurfaceHolder.Callback {
        public MySurfaceView(Context context) {
            super(context);
            getHolder().addCallback(this);
        }

        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { }

        @Override
        public void surfaceCreated(SurfaceHolder holder) { }

        @Override
        public void surfaceDestroyed(SurfaceHolder holder) { }
    }
}
</code></pre>

<p>Now a have to translate this code to Delphi. Java code is classes only, but Delphi's JNI is interfaces AND classes so I can't figure out how to represent this:</p>

<p><code>class MySurfaceView extends SurfaceView implements SurfaceHolder.Callback</code></p>

<p>since both JNI's <code>JSurfaceView</code> and <code>JSurfaceHolder_Callback</code> are interfaces.</p>

<p>So, does anybody knows how do do this? (or completely another way to access camera)</p>