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: 3,989
Last edited:

joneden

Active Member
Licensed User
Longtime User
Hi Erel,

I'm finding that after the release event the camera object takes a while to fully shutdown. My scenario is as follows:

1) User presses a clock in button
2) ZXing scanner launched and user can scan their barcode
3) Control returns to app. The camera is initialised and a picture is taken of the user, at this stage the camera object is closed.
4) A cancel button is now shown with the username so that the user can cancel the event.
5) After 5 seconds the cancel button disappears and the someone can now use the Clock in/out buttons.

My problem appears when the user presses the cancel button then immediately presses one of the clock in or out buttons. At this stage I get an error from the ZXing app stating that an error occurred with the camera.

I've done some tests and if the time between the camera.release call and the ZXing launch is less than 5 seconds the ZXing app crashes.

Any pointers on this?

Best Regards

Jon
 

joneden

Active Member
Licensed User
Longtime User
Erel that is fantastic thank you very much!

I've just run the app and now it works very well. Now if only killing a ABZXing invoked intent was as easy :)

Regards,

Jon
 

wheretheidivides

Active Member
Licensed User
Longtime User
You are correct. The cameras are only closed after 5 seconds. This allows your app to quickly reopen the camera when the orientation changes.

Add this code to CameraEx and call it:
B4X:
Public Sub CloseNow
   cam.Release
   r.Target = cam
   r.RunMethod2("releaseCameras", True, "java.lang.boolean")
End Sub

I have the same problem (I think). So in your camera example, where do make this call???? From here like this????

B4X:
Sub Button2011Camera_Click
'-----------------------------------------------
   CamEx.Release
   CamEx.CloseNow
   
   FrontCamera = Not(FrontCamera)
   InitializeCamera

'-----------------------------------------------
End Sub

This still freezes on me,
 
Last edited:

BukoCharly

Member
Licensed User
Longtime User
No Autofocus on Samsung Galaxy Camera...

Hi Folks,

for my job I need a camera where I can give numbers to the photos while saving. So I bought a Samsung Galaxy Camera and basic4android.... ;-)

I tried this camera example, everthing works fine on a Samsung Note 2, Asus Tab but not on the Samsung Galaxy Camera.

The program works, but the autofocus doesnt. The supported focus modes are:

auto, infinity, macro, fixed, face-detection, continuous, manual, multi, touch, object-tracking

So I tried to set the focus to the modes above with the SetFocusMode from the camera V2.1 class - but nothing works. Any camera app from the Google store works perfect with autofocus - but not this example... :sign0137:

Anybody has an idea? Thanks alot in advance...

Best, Buko
 

BukoCharly

Member
Licensed User
Longtime User
Thats my problem... :BangHead:

It only doesnt work on the Samsung GALAXY Camera EK-GC100, on all my other Samsung devices (Note 2, Note 10.1, Galaxy S2 & S3) the autofocus works fine - but not on the Camera.

Maybe the problem is that the camera supports only continuous mode instead of the continuous-picture & continuous-video mode like in the example, but no idea how I can change this - but I have to say - I am brand new in programming...
 

BukoCharly

Member
Licensed User
Longtime User
Allready tried this way. The modes I get back in the log if I ask device for supported modes are:

auto, infinity, macro, fixed, face-detection, continuous, manual, multi, touch, object-tracking

After I got this info I tried to set the Samsung Galaxy Camera in this mode instead of the continuous-picture & continuous-video mode using your example - but then they focus stops working.

This problem occures on all device I tested (Samsung Galaxy Camera, Samsung S3 & S2, Ausus TAB ...) The focus works fine if I use continuous-picture & continuous-video, but stops working if I use an other supported mode like the both above - for example macro or infinity.

I think that the problem with the Samsung Galaxy Camera is that it doesnt have the continuous-picture & continuous-video modes, it only has the mode called "continuous".

But it seems that the class will ony set the mode if its name is continuous-picture or continuous-video, which the Samsung Galaxy Camera doesnt have.

Thanks alot for helping, Michael
 

BukoCharly

Member
Licensed User
Longtime User
Hi Erel,

which code? Of the example? This I allready tried, but no function. Or the code of the class?



Sorry for stupid question.... ;-)
 

BukoCharly

Member
Licensed User
Longtime User
Hi Erel, I am new - but not that new... :icon_clap:

I add a button to your example where I can toggle thru all focus modes the camera has. That works fine on the Galaxy S3 and every other device I tested.

But on the EK-GC100 Samsung GALAXY Camera no chance to get the focus to work. I checked it with some apps from the store - this one work fine with the camera, but the cameraEX wont. Seems the camera is not compatible to this class. :sign0148:

How can we add a support of these camera to the class? Hire a programmer? Or is there now way?

Best, Buko
 

BukoCharly

Member
Licensed User
Longtime User
Hi Erel,

thanks for your support and patience. I will give you an overview what I tried. I took you example and add toggle button for the focus like yours for effects, flash and picture size. Then I tried this code (changing fuctions in runtime) on some devices:

Device............................ Pictureeffect.....Flash......PictureSize....Focus
Samsung S3.....................works ..............works.....works...........works
Asus TAB.........................works...............works.....works...........works
Samsung Galaxy Camera.....works...............works.....works...........dont work

So everything works fine on every device, only the focus wont work on the Galaxy Camera EK-GC100. If I press the focus toggle button I can switch thru the available focus modes (auto, infinity, macro, fixed, face-detection, continuous, manual, multi, touch, object-tracking) but no change in the preview window like the pictures effects - and no focus.

I tried all focus modes seperatly in the Public Sub SetContinuousAutoFocus but nothing happens.

I changed the place of the camEx.SetContinuousAutoFocus in the Sub Camera1_Ready part of the code - but no change.

It seems to be a timer problem, because then I tried - desperate as I was - the ACL - library.

There was a funny effect - if I make a picture the autofocus still doesnt work. But if I add a button where I call camera1.Focusmode = "AUTO" the picture in the preview window is sharp, if I make a picture then it is sharp.

But if I add the camera1.Focusmode = "AUTO" direct to a button with the camera1.TakePicture order is stops working again...

I tried everything - I think so - but now im out of ideas....

Best, Buko
 

Mahares

Expert
Licensed User
Longtime User
post#78, page 8 of this thread:
http://www.b4x.com/forum/additional...x-extends-camera-library-functionality-8.html

Erel says: I will add a method to CameraEx to load Jpeg images with the correct orientation.
I have a Samsung Galaxy Tab 2, 7 inch When the picture is viewed using any photo viwer/editor, the photo is always 90 degrees tilted to the left. It needs to be tilted to the right to correct it. On other devices, no problem. I tried different layouts and still nothing helped. I hope Erel or someone can help by giving me a tip or updating the 1.01 CamEx class.
Thank you
 
Status
Not open for further replies.
Top