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: 2,067
  • ACL4.5.zip
    33.5 KB · Views: 1,483
  • ACL4.6.zip
    359.4 KB · Views: 4,999
Last edited:

Omar

Member
Licensed User
Longtime User
Hello XverhelstX

I think you are right, I tried the code:

Msgbox(Camera1.getSupportedFlashMode,"")


and I received the same error message again: java.lang.NullPointerException

I think this may be a device issue. Thank you for all your help though.
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hey Omar,

Could u try out the library included in the attachment?
I changed the API level to 8 (V2.2+), but some features won't work.

Extract the 2 files in your library folder and don't forget to uncheck the AdvancedCamera in your IDE and check the AdvancedCamera8 in libs.

See the list here: Camera.Parameters | Android Developers
Api level:
Android API Levels | Android Developers

and you will see what is supported or not. (Scroll down and at the right side, you will see since what API Level.

EDIT: I also added API 7 (V2.1+). First try the 8 as it has to work on yours.

XverhelstX
 

Attachments

  • AdvancedCamera8.zip
    27.2 KB · Views: 479
Last edited:

Omar

Member
Licensed User
Longtime User
Hello XverhelstX

Thank you for the update files, I tried both versions. However unfortunately the same error is still occurring with: java.lang.NullPointerException

This occurs immediately on the line where I call the Camera1.FlashOn() or any Camera1 subroutine.

I think this has to be a device related matter but unfortunately I have no other Android device to test on.
 

Omar

Member
Licensed User
Longtime User
I just made a simple file as follows:

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

End Sub

Sub Activity_Create(FirstTime As Boolean)

   'Msgbox(Camera1.getSupportedFlashMode,"")
   camera1.FlashOn
   Msgbox("ok","ok")
   camera1.FlashOff()

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

I have enabled the AdvancedCamera8 Library in my code and tried separately with the original AdvancedCamera Library along with the AdvancedCamera7 library also. Each time it returns with the error: java.lang.NullPointerException

Thank you for your time to look into this.
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
I see,

it's related to your code., nothing to your device.
You have to follow the normal camera guidelines explained here:
Basic4android - Camera
and here:
http://www.b4x.com/forum/additional-libraries-official-updates/6892-new-camera-library-v1-00-a.html

and you can use just the normal camera library on the first page.

You can use this code below to see the features of the Advanced Camera Library.

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("Flash On","mnuFlashOn")
   activity.AddMenuItem("Flash Off","mnuFlashOff")
   activity.AddMenuItem("GetFlashMode","mnuGetFlashMode")

End Sub

Sub Activity_Resume

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

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

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.FlashOff
   camera1.StartPreview
   Dim out As OutputStream
   out = File.OpenOutput(File.DirRootExternal, "Picture.jpg", False)
   out.WriteBytes(data, 0, data.Length)
   out.Close

End Sub
Sub mnuFlashOn_Click

Camera1.FlashOn

End Sub
Sub mnuFlashOff_Click

Camera1.FlashOff
      
End Sub
Sub mnuGetFlashMode_Click

Msgbox(Camera1.getSupportedFlashMode,"")
   
End Sub

Sub mnuTakePicture_Click

camera1.TakePicture

End Sub

First you should go to the designer and add a Panel with a size of ...*...
(I use for example 480*320) and name it Panel1. Save the layout as Menu.
This is what Activity.Loadlayout("Menu.bal") does. It loads your menu created with the designer.

Then you can see the activity.AddMenuItem("Flash On","mnuFlashOn"). this adds a menu field on your phone's screen. You can open this when you press the menu hardware button on your mobile phone (next to your back and 'home button).
As you can see it exists of two parts in strings: ("Flash On","mnuFlashOn")

"Flash on" is the text that will appear on the screen when you press the option hardware button.
"mnuFlashOn" handles in your activity when you pressed it. This is called in a sub with _Click behind it. Just like with buttons.

B4X:
Sub mnuFlashOn_click 
Camera1.FlashOn
'note the _Click behind the sub.
End sub

So when you press on the menu field on the screen, it activates the sub mnuFlashOn_Click and so activates the Camera1.FlashOn.

Note that I just use Activity.AddmenuItem as it is easier for me.
You can cast all features of the Advanced Camera Library on any other thing like buttons, ...

All the rest of the code should be explained here:
http://www.b4x.com/forum/basic4andr...-take-pictures-internal-camera.html#post39830

One thing you shouldn't forget is to go to Projects - orientations supported - Landscape.

Hope I helped you ;)

Sincerely,
XverhelstX
 
Last edited:

Omar

Member
Licensed User
Longtime User
Dear XverhelstX

Yes, you have been a great help.

Thank you very much for your detailed explanation again. You have been a great help.

Thank you once again as I would have not figured it out on my own.
 

XverhelstX

Well-Known Member
Licensed User
Longtime User

NeoTechni

Well-Known Member
Licensed User
Longtime User
I'm having trouble setting things like coloreffects, antibanding or switching cameras. Are there any requirements? ie: Do I have to stop the preview, then restart it? Cause just setting the value does nothing. And when I use getCurrentColourEffect, it returns "none" and getCurrentAntibanding returns nothing

Also, I like the suggestion of combining the gets and sets into a single function. It's cleaner
 
Last edited:

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hey neotechni,

You can use .getsupportedeffects to see what effects your device can handle.
When using current, it shows what technique the camera is using now. In your case:
None.

You can find an example at the bottom of the first post.
I Will also change the gets and sets as one then later.

XverhelstX
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
You can use .getsupportedeffects to see what effects your device can handle.
When using current, it shows what technique the camera is using now. In your case:
None.

I have been using that, I use that list to populate an inputlist so the user can only pick from what's supported. And none of them change the effect on screen, and all of them return 'none' when I check it.

I will check the example, but I should be able to set them at any time...
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
I tried uppercasing it, no difference.
Do the quotes need to be in the string itself?

What I do is take the getsupported list as a string, cut off the first and last characters ( [ and ] ) split it by ", " into an array, pass that array to inputlist, and use cam.setColourEffect = list(selecteditem).touppercase
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
I am doing that.

The getsupported list? I'm passing it into an inputlist so the user can select from any of the items in the list.

The one they select is capitalized, and sent back to the camera object, and I still get none when I check it.

Its not working.
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
screen
 

Attachments

  • sepia.jpg
    sepia.jpg
    79.3 KB · Views: 288
Top