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

michelrom22

New Member
Licensed User
Longtime User
Tablet PC

Hi all, any idea why the code is giving an error when using a tablet ? The error is on line " camera1.StartPreview ". Thanks in advance
 

bluedude

Well-Known Member
Licensed User
Longtime User
Save camera picture to DCIM/Camera

Hi,

I'm trying to save pictures taken to DCIM/Camera but not sure if this works with File.DirRootExternal. Pictures are saved but cannot find them anywhere.

Cheers,
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
CameraEx v1.01 is attached to the first post.

- More features are supported.
- CameraEx correctly handles devices with only front camera.
- The demo was improved.

Note that the camera library was also updated (v2.01): http://www.b4x.com/forum/additional.../23799-camera-library-v2-00-a.html#post137747

@bluedude, see the new version. It forces the media scanner to scan the saved file. This will in most cases cause Windows Explorer to show the file. If you still do not see it then you should disconnect the USB cable and connect it again.
 

bluedude

Well-Known Member
Licensed User
Longtime User
I tried that a few times but it isn't working. Isn't it possible to physical write camera pictures to DCIM/Camera?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Try this code:
B4X:
ScanFiles(Array As String(File.Combine(File.DirRootExternal, "1.jpg")))

Sub ScanFiles(files() As String)
   Dim r As Reflector
   r.RunStaticMethod("android.media.MediaScannerConnection", "scanFile", _
      Array As Object(r.GetContext, files, Null, Null), _
      Array As String("android.content.Context", "[Ljava.lang.String;", "[Ljava.lang.String;", _
         "android.media.MediaScannerConnection$OnScanCompletedListener"))
End Sub
 

Mahares

Expert
Licensed User
Longtime User
@Erel: The IDE still shows Camera version 2.00 instead of 2.01 even after update of the lib. Are you good with that?

@BlueDude: It works fine for me too. Here are some examples:
B4X:
Dim dir As String = "/mnt/sdcard-ext/DCIM/camera"  'root of device SD card plus /DCIM/camera folder  'Replace /mnt/sdcard-ext with your SD root.

Also this:
B4X:
Dim dir As String = File.DirRootExternal
dir=dir & "/DCIM/camera/"
Am I missing something Dude?
 

bluedude

Well-Known Member
Licensed User
Longtime User
Will try a few more things, I really want my pictures to be in DCIM/Camera.

Thanks!
 

thedesolatesoul

Expert
Licensed User
Longtime User
I had some problem with this library. When I press on Take Picture, the app locked up. The button remained pressed, and nothing was happening. I quit the app and destroyed the process. But after that my camera was unaccessible.
Although, I dont think it may be related, but after that a few hours later my phone completely crashed and is stuck in a boot loop.
Not sure what I did wrong, its a Galaxy S running CM9 (well it was, now i have to reflash).
Probabaly a specific manufacturer issue with my phone.
 

awama

Active Member
Licensed User
Longtime User
I had some problem with this library. When I press on Take Picture, the app locked up. The button remained pressed, and nothing was happening. I quit the app and destroyed the process. But after that my camera was unaccessible.
Although, I dont think it may be related, but after that a few hours later my phone completely crashed and is stuck in a boot loop.
Not sure what I did wrong, its a Galaxy S running CM9 (well it was, now i have to reflash).
Probabaly a specific manufacturer issue with my phone.

I have exact the same problem. I have to reboot to get camara-function return.
But the malfunction is only sometimes.

When I compile, while the screen is locked, it comes also to malfunction (message camera can not open, but that is always.)

I have testet on Samsung Galaxy S2, 4.0.3
 

korshkov

Member
Licensed User
Longtime User
Hello!
How can I use a class for realtime checking visible camera image for motion detect?
I try use Timer and Panel1.Background for checking current image....
And nothing result.
This is right? Or Panel1.Background not containg image?
Please specify the direction of digging :)
Thanks!

P.S. And excuse me for my bad English.
 

awama

Active Member
Licensed User
Longtime User
Can you check the unfiltered logs and see whether there are any errors there?

Now I could reproduce the error. Here a part of the unfiltered logs:

last log message of the camera
...
GC_FOR_ALLOC freed 450K, 9% free 10162K/11143K, paused 26ms
LSIHAL void android::HAL_camera_device_enable_msg_type(camera_device*, int32_t)
GC_CONCURRENT freed <1K, 5% free 10612K/11143K, paused 2ms+3ms
LSIHAL void android::HAL_camera_device_disable_msg_type(camera_device*, int32_t)
GC_FOR_ALLOC freed 450K, 9% free 10162K/11143K, paused 26ms
LSIHAL void android::HAL_camera_device_enable_msg_type(camera_device*, int32_t)
GC_CONCURRENT freed <1K, 5% free 10612K/11143K, paused 2ms+3ms
LSIHAL void android::HAL_camera_device_disable_msg_type(camera_device*, int32_t)
dispatchTouch::touch event's action is 0 (deviceType=0) [pCnt=1, pending(waiting finished signal)=0]
Delivering touch to current input target
Delivering touch to current input target
Delivering touch to current input target
GC_FOR_ALLOC freed 450K, 9% free 10162K/11143K, paused 35ms
LSIHAL void android::HAL_camera_device_enable_msg_type(camera_device*, int32_t)
GC_CONCURRENT freed <1K, 5% free 10612K/11143K, paused 2ms+3ms
dispatchTouch::touch event's action is 1 (deviceType=0) [pCnt=1, pending(waiting finished signal)=0]
Delivering touch to current input target
Delivering touch to current input target
LSIHAL void android::HAL_camera_device_enable_msg_type(camera_device*, int32_t)
virtual android::status_t android::SecCameraCoreManager::takePicture():stop IT Policy checking thread
LSIHAL int android::HAL_camera_device_send_command(camera_device*, int32_t, int32_t, int32_t)
ShotSingle::takePicture start
LSIHAL int android::HAL_camera_device_take_picture(camera_device*)
takePicture E
takePicture: warning, preview is running
stopPreview E
id=765 Removed idx=8 Map Size=9
id=765 Removed idx=-2 Map Size=9
releaseWakeLockLocked flags=0x0 tag=KEEP_SCREEN_ON_FLAG myUID=1000 myPID=2003 myTID=2060
usb connection is true
...
 
Status
Not open for further replies.
Top