Call/delegate to Android Camera-app that returns image in Qt?
-
Hello, I am trying to develop an Qt app in Qt Widget that opens the stock/OEM Android Camera App so the user can take a photo and the app gets the returned photo, a QImage for example. (The image will be used in some kind of PDF report with text ect, but that might be another story)
I tried to create an app with the QCamera, QCameraImageCapture, QCameraViewfinder, QCameraInfo ect . But i realize that it might be a lot of work if i would implement settings like focus, exposure, zoom ect. It would be better to delegate to the existing "Android Camera"-functionality.
In native Android Studio you might use MediaStore.ACTION_IMAGE_CAPTURE https://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE
But i don't know what to use in Qt.Someone who know how to this in Qt?
-
@pga4711 said in Call/delegate to Android Camera-app that returns image in Qt?:
I am trying to develop an Qt app in Qt Widget
Is using Qt Widget a strict requirement? If not, you may want to take a look at this QML Camera example.
-
In Qt for Android, you can :
- add AndroidExtras to benefit from an API in order to start an Activity and receive the result in a C++ callback.
- use JNI to do the same, in order to add specific stuff that would be available in Java only (as using a SDK available in Java and not C++).
-
@Pablo-J.-Rogina said in Call/delegate to Android Camera-app that returns image in Qt?:
@pga4711 said in Call/delegate to Android Camera-app that returns image in Qt?:
I am trying to develop an Qt app in Qt Widget
Is using Qt Widget a strict requirement? If not, you may want to take a look at this QML Camera example and QML Camera Example. The camera "realtime image flow" seems to work in the QML example but not in the Qt Widget Camera Example
As it looks now, it would be good if i try to do things with Qt Widget, because my fellows around me understands that. But if things don't work so well in Qt Widget i might have a look at QML. There might be a 2-3 days learning curve for introduction in QML?
I hade a look at both Camera Example and QML Camera Example. The problem is that there is no “real time camera image flow” in the Qt Widget Camera Example. Someone who know why? It might be a known problem?
Another thing: What is QCameraViewfinder ? It feel very abstract. Is it a view where we can put images in or what? :>
@SR__ said in Call/delegate to Android Camera-app that returns image in Qt?:
In Qt for Android, you can :
- add AndroidExtras to benefit from an API in order to start an Activity and receive the result in a C++ callback.
- use JNI to do the same, in order to add specific stuff that would be available in Java only (as using a SDK available in Java and not C++).
I think your recommendation is very good.
I have tried some small steps with this small scale example about choosing picture from Android Gallery. There were/are some issues. I changed the “Minimum required SDK” to “API 19” and “Target SDK” to ”API 26”, so now things will compile and make.
And now i can run the example. I feel very dizzy about these lines for example:
selectedFileName = "#";
QAndroidJniObject::callStaticMethod<void>("com/amin/QtAndroidGallery/QtAndroidGallery",
"openAnImage",
"()V");
while(selectedFileName == "#")
qApp->processEvents();The selectedFileName always contains the empty string :(
Someone who have ideas how to proceed next? :) For example, what is wrong with the Qt Widget Camera Example, and how to get directory path from openAnImage-method ...
-
While it has gotten a lot better to use JNI methods with Android, I still avoid them whenever possible. Especially, when I wish to support iOS, also; and Windows/Mac tablets...all with identical code, only minor tweaks for install.
I've found the Qt camera (Widgets or QML) to work well - even realtime viewing, just re-using big chunks of the example code. The zoom/white balance/focus controls automatically show, or not, as the actual device is able to support them.
The secret that made it all work much easier for me, was to avoid the un-necessary extra signal/slot stuff for a simple picture....mycamerainstance.captureToLocation(myValidLocalFilename);
I'd suggest trying skipping the platform camera, and trying the Qt Camera again, using the simpler captureToLocation call. I've found this way simplest.
Good luck!