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,942
  • ACL4.5.zip
    33.5 KB · Views: 1,382
  • ACL4.6.zip
    359.4 KB · Views: 4,870
Last edited:

NJDude

Expert
Licensed User
Longtime User

Steini1980

Active Member
Licensed User
Longtime User
The're many Methods implemented, but I can't find an interface which allows to work with AutoExposureLock.

ExposureCompensation is implemented, but in dependency with android device it's just possible to correct the ExposureCompansation +/-2.
The requirements of my customer is always to take photos with back light (e.g. doors and windows from inside), so it's necessary to have a greater scope to adjust camera settings such as the Exposure.
 

Andrey Lopatin

New Member
Licensed User
Longtime User
Hello.
Did anyone try to create flashlignt app for Nexus 5? I tried cam.FlashTorch, then cam.toggleFlashLight functions. Both with no success. Flashlight simply does not turn on, nothing happens. cam.SupportedFlashMode shows "off, auto, on, torch" are avalaible.
 

tmf

Member
Licensed User
Longtime User
I would like to take a 256x256 pixel image and save it as JPG, can this be done, I have read through this and it seems it will save it at the max resolution of the camera?? any examples for this??

Thanks!
 

dataware

Member
Licensed User
Hi, i hope someone should help me with this, when i implement this on another program code, throw me an error message like this:

sub.main_some_function(B4a line:"some_line")
camera.initialize(some_panel, "some_name")
java.lang.ClassCastException:android.widget.Button
cannot be cast to android.view.SurfaceView

and am doing some like this

B4X:
Sub capture_Click
    Try
        LoadLayoutIntoActivity("camera")
        Dim camera As AdvancedCamera
        camera.initilize(panel1,"camera_event")
        camera.StartPreview
       Catch
        ToastMessageShow("Error", True)
    End Try
End Sub

i dont wonna put "camera.initilize(panel1,"camera_event")" on "resume" activity because it send me another error when i dont call the activity at start

for your comments, thanks
 
Top