B4A Library Android Dual Camera

It is a wrap for this Github project. I came across it while I was looking for some additional code for this project:

https://www.b4x.com/android/forum/t...has-flash-inline-java-code.66427/#post-427412 - it will start up both the front and back cameras of devices that support this functionality and display both camera previews simultaneously (functionality that is supported by for eg the HTC One M8).

This project is however not related to devices that support this type of functionality (mostly hardware functionality) but rather a project that allows you to:
1. take a photo with the back camera,
2. then take a photo with the front camera,
3. then add some text via a dialog
a. set the text size via a slider
b. set the text color via a color picker
c. enter the text to be added to the picture​
4. save the combined front/back/text into a single image
5. Share the image via one of numerous standard apps​

The combined image will be saved in your device's /pictures folder (in a sub folder called dualCam)

You will need android-support-v4.jar in your additional library folder. Posting the following:
1. B4A project
2. B4A library files

Take note of the files inside the /Objects/res/blabla... folders of the B4A project. Make sure they are set to READ ONLY before you run the project.

When the app starts, click on the Start Scan button. The back camera will be activated. Now click on the icon (camera + heart) to take a snapshot with the back camera.
1.png




The front camera is started automatically once the back camera pic has been taken. Click on the icon (camera + heart) to take a picture with the front camera.
2.png



The following dialog will appear - click on Yes
3.png



Enter your text in the text box, use the slider to set the text size, and then click on Select a Font Color
4.png


5.png



Pick a text color in the outer ring and click the centre "bulls eye" once you have selected your color from the outer ring
6.png


I have selected Green....and then clicked on the Green "bulls eye"
7.png



The result....
8.png


....continuing in post #2
You can download and test it but if you want to use it you need to
 

Attachments

  • DualCamera_3LibFiles.zip
    44.3 KB · Views: 188
  • b4aAndroidDualCamera_3.zip
    132.5 KB · Views: 197

Johan Schoeman

Expert
Licensed User
....continuing from post #1

Click on the Save icon (stiffy) - a toast message will appear saying that the image has been saved
9.png


Note that the color of the Share icon has changed once the image has been saved

Click on the "reddish" Share icon and choose from one of the default apps to share the image with
10.png


Once the pic has been "Shared" (email, whatsapp, or whatever you chose) the B4A app will be ready to be started again:
12.png
 
Last edited:

ilan

Expert
Licensed User
hi johan, when i try your example i get this error:

** Activity (main_scanner) Create, isFirst = true **
** Activity (main_scanner) Resume **
** Activity (main_scanner) Pause, UserClosed = false **
java.lang.RuntimeException: Method called after release()
at android.hardware.Camera.setPreviewSurface(Native Method)
at android.hardware.Camera.setPreviewDisplay(Camera.java:679)
at com.cam.dualcam.view.CameraPreview.surfaceCreated(CameraPreview.java:34)
at android.view.SurfaceView.updateWindow(SurfaceView.java:606)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:184)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:895)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2153)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1180)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6558)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
at android.view.Choreographer.doCallbacks(Choreographer.java:590)
at android.view.Choreographer.doFrame(Choreographer.java:560)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5832)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
 

ilan

Expert
Licensed User

ilan

Expert
Licensed User
ok the second time i tried it it worked.
but only the back camera is activ and i get a toastmessage: Something is wrong with the camera setting: CAUSE = setParameters failed

does it means that my phone (Samsung S5) does not support both camera to be on?
 

Johan Schoeman

Expert
Licensed User
ok the second time i tried it it worked.
but only the back camera is activ and i get a toastmessage: Something is wrong with the camera setting: CAUSE = setParameters failed

does it means that my phone (Samsung S5) does not support both camera to be on?
No, only one camera at a time. If you click on the icon in the centre (the camera with the heart inside) it should take a snapshot with the back camera and then start the front camera at the bottom half (where the block with Preview Front Camera is). Then click on the icon (camera with heart) to take a snapshot with the front camera.
 

Johan Schoeman

Expert
Licensed User
ok the second time i tried it it worked.
but only the back camera is activ and i get a toastmessage: Something is wrong with the camera setting: CAUSE = setParameters failed

does it means that my phone (Samsung S5) does not support both camera to be on?
I saw the same thing just now....I need to trap this "first start" error that occurs. Had the same error once I have "shared" the image wit Google mail but got that one sorted out. This happening upon startup is "new" - will dig into it...
 
Top