B4A Library [Class] CameraEx - Extends the camera library functionality

Status
Not open for further replies.
Example based on B4XPages: https://www.b4x.com/android/forum/threads/b4x-b4xpages-barcode-reader.120417/#content

CameraEx class wraps the Camera object and using reflection and other code it extends its functionality.

CameraEx class requires Android 2.3+ and depends on Camera library v2.20+
CameraEx features:
  • Easily open the back or front camera
  • Preview images and saved images orientation will match the device orientation (all orientations are supported)
  • Gives access to Camera.Parameters native class (flashmode, picture size, effects and other settings)
  • Includes methods to convert preview images to JPEG and to save the taken pictures.
  • It should be simple to add more methods to this class

SS-2012-11-28_12.18.31.png


See this page for the constant values and other possible methods:
https://developer.android.com/reference/android/hardware/Camera.Parameters.html

Note that you should call CommitParameters after changing one or more parameters.

CameraExClass module is included in the attached example.

V1.30 is attached - Includes various new methods.

v1.20 - Includes all the various posts in this thread as well as AutoFocusAndTakePicture method which first calls AutoFocus and then takes a picture (if AutoFocus was successful).

Edit (06/2018): A new version was uploaded with targetSdkVersion set to 26.
 

Attachments

  • CameraEx.zip
    13.2 KB · Views: 4,026
Last edited:

Adam888

Member
Licensed User
Longtime User
Hi, Erel,

If I want to mirror the front camera in preview mode (not take picture and post process),How can I do ?

Thanks
 

Adam888

Member
Licensed User
Longtime User
Yes, Sure
So , I need to mirror again.
Can you tell me how to do that? Thank you very much.
 

Adam888

Member
Licensed User
Longtime User
Thank you, I modify SetDisplayOrientation , and my program can rotate the preview.
Could you please tell me how to mirror in x axis (horizontal flip)?
 

ednt

Member
Licensed User
Longtime User
I test the new Version 3.00 BETA 1 with the Camera Example.

The Autofocus do not work with the new Version.
The Android Appliaction is complete Stoping.

Only Picture withous Foucs is working.
Someone with the same issue ?

i try the CameraEX.zip & CameraEX_JB.zip example with a Samsung SII Device.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User

Adam888

Member
Licensed User
Longtime User
Hi Erel,

Sorry, the two methods still rotation only.
Please refer to attached picture. I want to flip the picture in preview mode.

Does the panel object can flip with camera?

Thank you
 

Attachments

  • Screenshot_2013-10-07-14-58-27.png
    Screenshot_2013-10-07-14-58-27.png
    444.9 KB · Views: 254

aeropic

Active Member
Licensed User
Longtime User
Hi Erel,

Based on CameraEx and Jim Brown's v1.21 excellent work, I've added my modest contribution to CameraEx class :confused:

Additional subs added:
  • getExposureCompensationStep
    Gets the exposure compensation Step.
    Applications can get EV by multiplying the exposure compensation index AND Step. Ex: If exposure compensation index Is -6 AND Step Is 0.333333333, EV Is -2
  • getExposureCompensation
    Gets the current exposure compensation index.
    The range Is getMinExposureCompensation() To getMaxExposureCompensation(). 0 means exposure Is Not adjusted.

  • getMaxExposureCompensation
    Gets the maximum exposure compensation index.
    maximum exposure compensation index (>=0). If both this method AND getMinExposureCompensation() Return 0, exposure compensation Is Not supported.

  • getMinExposureCompensation
    Gets the minimum exposure compensation index.
    minimum exposure compensation index (<=0). If both this method AND getMaxExposureCompensation() Return 0, exposure compensation Is Not supported.

  • setExposureCompensation (Int value)
Also the Camera_LogFeatures added by Jim is modified to include this :

Exposure compensation options________
Expo step : 0.5
Expo compensation : 0
Expo compensation min : -4
Expo compensation Max : 4

Everything has been tested and works fine on my Galaxy S3

I intend to introduce this inside my CameraUnlock application but this is another story ! http://www.b4x.com/android/forum/threads/camera-unlock.34156/

Bye
Alain
 

Attachments

  • CameraEx3.zip
    267 KB · Views: 370
Last edited:

jim0406

New Member
Licensed User
Longtime User
Hi,
can i use the camera.lib and cameraex.lib with Nikon Coolpix S800c Camera?
(from tech specs:
The S800c is a full Android 2.3 (known as Gingerbread) device, meaning it can run any apps that an equivalent smartphone could offer - so you can run Photoshop Express to spruce-up your images, rather than being dependent on the manufacturer-supplied processing options. For that matter, there's nothing to stop you passing the time with a quick game of Temple Run or Fruit Ninja. You'll control all of this on the camera's 3.5" touchscreen OLED display)

thank you
 

ChrShe

Member
Licensed User
Longtime User
I'm getting NoSuchFieldError from the SetDisplayOrientation that gets called.
I should say that this is in the emulator. Unfortunately, currently that is my only option for testing code...So I don't know if it happens on a real device. :(

It's failing here:
B4X:
Private Sub SetDisplayOrientation
    r.Target = r.GetActivity
...
...
Here's what the log comes up with:
B4X:
** Activity (actnewmed) Resume **
cameraexclass_setdisplayorientation (B4A line: 92)
r.Target = r.GetActivity
java.lang.NoSuchFieldError: anywheresoftware.b4a.BA.activityBA
    at anywheresoftware.b4a.agraham.reflection.Reflection.GetActivity(Reflection.java:638)
    at com.MyRXList.shenarsoft.cameraexclass._setdisplayorientation(cameraexclass.java:889)
    at com.MyRXList.shenarsoft.cameraexclass._camera_ready(cameraexclass.java:153)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:151)
    at anywheresoftware.b4a.objects.CameraW$2$1.run(CameraW.java:139)
    at android.os.Handler.handleCallback(Handler.java:605)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4424)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)

Any ideas?
 
Last edited:

ChrShe

Member
Licensed User
Longtime User
I thought the latest...but Reflection is version 1.90.

I'll double check my versions and report back...Thank you!
 
Status
Not open for further replies.
Top