B4A Library Advanced Camera Library V1.00

UPDATE! - Zoom, Current & Supported - Advanced Camera Library V2.00

Hello everyone!

B4X:
Sub Globals
Dim camera1 As AdvancedCamera ' New lib
End Sub


I'm glad to announce my fourth library! :D
This library is a modification of the existing camera library with more options.
So the standard procedures of the camera still apply.
Basic4android - Camera

You can find the Advanced Camera Library in the attachements.
To use: Extract and Copy the Advanced Camera.xml and Advanced Camera.jar to the library folder in "Anywhere Software\Basic4android\Libraries".

.:!BIG UPDATE!:.
Advanced Camera Library has been updated to version 2.0 with tons of new features!
See post #19
http://www.b4x.com/forum/52479-post19.html


.:Index:.


[1] Flashlight
[2] Camera's
[3] Orientation
[4] Pictures
[5] Antibanding
[6] Colour Effects
[7] Focus Mode
[8] Scene Mode
[9] White Balance


So, let's start

1) Flashlight

a.
"FlashAuto": Enables the flashlight to turn on automatically.
B4X:
Camera1.FlashAuto()

b.
"FlashOn": Turns the flashlight on.
B4X:
Camera1.FlashOn()

c.
"FlashOff": Turns the flashlight off.
B4X:
Camera1.FlashOff()

2) Camera's

a.
"CameraBack": Sets the back camera as primary camera.
B4X:
Camera1.CameraBack()

b.
"CameraFront": Sets the front camera as primary camera.
B4X:
Camera1.CameraPortrait()

3) Orientation

a.
"OriLandscape": Sets the orientation to landscape mode.
B4X:
Camera1.OriLandscape()

b.
"OriPortrait": Sets the orientation to portrait mode.
B4X:
Camera1.OriPortrait()

4) Pictures

a.
"PictureSize": Sets the size of the picture in pixels.
The parameters must be modified before Camera1.StartPreview.
B4X:
Camera1.PictureSize(480,320)

b.
"Quality": Sets the quality of the JPEG picture. Range between 0 - 100, with 100 being the best.
The parameters must be modified before Camera1.StartPreview.
B4X:
Camera1.Quality = 100

5) Antibanding

"setAntibanding": Sets the Antibanding. This is used to remove noises like when you take a picture of a monitor/television screen.
  • ANTIBANDING_50HZ: Sets the antibanding to 50Hz.
  • ANTIBANDING_60HZ: Sets the antibanding to 60Hz.
  • ANTIBANDING_AUTO: Sets the antibanding to automatic mode.
  • ANTIBANDING_OFF: Sets the antibanding off.
B4X:
Camera1.setAntibanding = "ANTIBANDING_AUTO"

6) Colour Effects

a.
"setEffect": Sets the color effect of your picture.
  • AQUA
  • BLACKBOARD
  • MONO
  • NEGATIVE
  • NONE
  • POSTERIZE
  • SEPIA
  • SOLARIZE
  • WHITEBOARD
B4X:
Camera1.setEffect = "SEPIA"

7) Focus Mode

"setFocusMode": Sets the focus mode of your picture.
  • MACRO: Close-up.
  • INFINITY: Far distance.
  • FIXED: If the camera has auto-focus, this mode can fix the focus.
  • AUTO: Auto-focus mode.
  • EDOF: Focusing is done digitally and continuously.
B4X:
Camera1.setFocusMode = "MACRO"

8) Scene Mode

"setSceneMode": Sets the scene mode of your picture.
  • ACTION: Take photos of fast moving objects.
  • AUTO: Scene mode is off.
  • BEACH: Take pictures on the beach.
  • CANDLELIGHT: Capture scenes lit by candles.
  • FIREWORKS: Take pictures of fireworks.
  • LANDSCAPE: Take pictures on distant objects.
  • NIGHT: Take photos at night.
  • PARTY: Indoor low-light shot.
  • PORTRAIT: Take people pictures.
  • SNOW: in the snow.
  • STEADYPHOTO: Avoid blurry pictures (handshake).
  • SUNSET: Take Sunset photos.
  • THEATRE: Take photos in a theater.
B4X:
Camera1.setScene = "BEACH"

9) White Balance

"setWhiteBalance": Sets the white balance of your picture.
  • AUTO
  • CLOUDY_DAYLIGHT
  • DAYLIGHT
  • FLUORESCENT
  • INCANDESCENT
  • SHADE
  • TWILIGHT
  • WARM_FLUORESCENT
B4X:
Camera1.setWhiteBalance = "WARM_FLUORESCENT"


If there are any bugs, questions or features you want to add to the library, please post them on this forum.

Credits and feedback are really much appreciated!

Thank you very much!

XverhelstX

Full example:

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   
   Dim camera1 As AdvancedCamera
   Dim Panel1 As Panel
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
    
   Activity.LoadLayout("Menu")
   activity.AddMenuItem("Take Picture","mnuTakePicture")
   activity.AddMenuItem("Set Effect","mnuSetEffect")
   activity.AddMenuItem("Flash On","mnuFlashOn")
   activity.AddMenuItem("Focus Mode","mnuFocusMode")
   
End Sub

Sub Activity_Resume
   
   camera1.Initialize(panel1, "Camera1")
   
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   camera1.StopPreview
   camera1.Release
End Sub

Sub mnuFlashOn_Click

camera1.FlashOn()
End Sub

Sub mnuSetEffect_Click

Camera1.setEffect = "SEPIA"

End Sub

Sub Camera1_Ready (Success As Boolean)
   If success Then
      Camera1.StartPreview
      
   Else
      ToastMessageShow("Cannot open camera.", True)
   End If
End Sub

Sub Camera1_PictureTaken (Data() As Byte)
   camera1.StartPreview
   Dim out As OutputStream
   out = File.OpenOutput(File.DirRootExternal, "Image.jpg", False)
   out.WriteBytes(data, 0, data.Length)
   out.Close
   ToastMessageShow("Image saved: " & File.Combine(File.DirRootExternal, "Image.jpg"), True)

   
End Sub

Sub mnuTakePicture_Click
   
   camera1.TakePicture
   
End Sub

Sub mnuFocusMode_Click
   
   camera1.setFocusMode = "MACRO"
   
End Sub
 

Attachments

  • ACL4.4.zip
    364.7 KB · Views: 1,950
  • ACL4.5.zip
    33.5 KB · Views: 1,394
  • ACL4.6.zip
    359.4 KB · Views: 4,879
Last edited:
D

Deleted member 103

Guest
Hi Tomas,

Thanks for the reply, a algorithm is determined not so easy. :(
 

Uitenhage

Member
Licensed User
Longtime User
Hi,

I am using ACL 4.6 in my app and have the following comments:

1. When rotating the phone 90 degrees clockwise the image is upside down.
2. When the phone is rotated 90 degrees the screen flashes black before settling in the new orientation. Is this a side effect of Activity_Pause and Activity_Resume in the library?
3. The saved picture orientation doesn't maintain the phone orientation and sometimes needs to be rotated which can generate OutOfMemory errors when using the ACL rotateBitmap function with big images.

Can these rotation/orientation issues more closely emulate the built-in camera?

Thanks,

Jim
 

Uitenhage

Member
Licensed User
Longtime User
Erel,

I tried using CameraEx class and it only solves #1 of post #244 - #2 & #3 both remain.

Thanks,

Jim
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
#2 is not avoidable. Internally the camera view is destroyed and recreated.

#3 was discussed in the CameraEx thread. Your camera can save the orientation in the EXIF headers. You can use the Jpeg library to find the correct orientation. I'm pretty sure that you can find the code in that thread that correctly loads the image.
Some viewers ignore the Exif headers. LoadBitmap will ignore it for example. So you need to do it manually.

You should start a new thread about the zoom issue.
 

lorebarita

Member
Licensed User
Longtime User
When I integrate the Advanced camera library in my app, The image preview appears rotate -90 degrees. How can I rotate the image to 0 degrees from the preview. I am able to rotate the image when saving but have a problem in preview of image before taking the photo. Thanks
 

dibesw

Active Member
Licensed User
Longtime User
I cannot set picture resolution when I want to save the picture.
I tried
B4X:
camera1.setResolution(480,320)
and
B4X:
camera1.PictureSize(480,320)
but all picture are saved 2560x1920 (I have Galaxy tab3).
The code is in Camera_ready before camera.StartPreview,
How can I do to save picture with low recolution?

THANKS!
 

LorenzoTRANSFEREX

Member
Licensed User
Longtime User
Hi, I am trying to use this amazing library and it is wonderful when it works, but my problem is that I am using the camera with ABZxing library too and when I initialize the ACL, the ABZxing can't access to camera.
I am trying with .release and .reconnect but the app crash with

java.lang.NullPointerException
at xvs.ACL.ACL.StartPreview(ACL.java:196)
...

Any ideas how works with both libraries together?


Thanks
 

Steini1980

Active Member
Licensed User
Longtime User
If I try to use this Library I get the following error:

Basic4android
---------------------------
An error occurred.
Error parsing libraries.
xvs.ACL.Base64.decode already exists.

Sorry I took not the latest Version, with 4.6 it's without error!
 
Last edited:

sotik

Member
Licensed User
Longtime User
Hi, when i do camera1.takePicture with flash on, it takes the picture before the flash be throwed, how can i fix it?

Another issue, i use camera1.FocusMode = "AUTO" but it doesn't work, and is supported on my phone.
 

daemon

Active Member
Licensed User
Longtime User
Can I use this library to access camera from a background service?
I cannot use CameraEx class to do so.
 

jsnieto

Member
Licensed User
Longtime User
With android 5, samsung galaxy s3

I cant use the library


java.lang.NullPointerException: Attempt to invoke virtual method 'android.hardware.Camera$Parameters android.hardware.Camera.getParameters()' on a null object reference
** Activity (main) Pause, UserClosed = false **


** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **


** Activity (main) Resume **


** Activity (main) Pause, UserClosed = false **


** Activity (main) Create, isFirst = false **


** Activity (main) Resume **


** Activity (main) Pause, UserClosed = false **


java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.ViewGroup.removeView(android.view.View)' on a null object reference


at xvs.ACL.ACL.Release(ACL.java:219)
at com.rootsoft.acl.main._activity_pause(main.java:313)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at com.rootsoft.acl.main.onPause(main.java:240)
at android.app.Activity.performPause(Activity.java:6044)
at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1294)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3211)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3184)
at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3159)
at android.app.ActivityThread.access$1000(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
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:898)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.ViewGroup.removeView(android.view.View)' on a null object reference
** Activity (main) Resume **


** Activity (main) Pause, UserClosed = true **
 
Top