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:

XverhelstX

Well-Known Member
Licensed User
Longtime User
Sorry Alfcen.
Updated to 4.1.
I updated the wrong library because my troubles with Android 2.1.
Where 2.1 doesn't support Angles.

Here you can see everything:
Camera.Parameters | Android Developers)

At the right side, you can see since when it was supported: API Level 8 = Android 2.2.

Android API Levels | Android Developers

If anyone want anything else added from here:
Camera.Parameters | Android Developers

post it here.

XverhelstX

EDIT:

in function Camera.detectFaces() you are now able to select where you want to store the new file using file. Also, the complete face is captured now.
 
Last edited:

alfcen

Well-Known Member
Licensed User
Longtime User
Hi XverhelstX

No problem whatsoever, now all is working absolutely fine. ACL comes in extremely handy for my first AR project, i.e. you move your phone along the sky and catch either the sun, moon or planets in the center of the FOV. For this to work at best accuracy the horizontal view angle is important to know. Also, thanks a lot for mentioning that 2.1 does not support angles. I was not aware of this fact.

You are doing truly great on this library. One can see how much affection you are devoting into your project.

As soon as I get my head around I will try Face Detection, using my fingerprint as my ugly face might irritate your library :cool:

Cheers
Robert
 

Attachments

  • device.jpg
    device.jpg
    17.8 KB · Views: 238

henrik

Member
Licensed User
Longtime User
Hi,

I have a question related to taking pictures from the preview:
I would like to change the preview-size, but can't figure out how-to.

I tested

setResolution(width,height)

and

getPictureOnCurrentFrame(width,height,quality)

with the preview-size settings supported from my device (GalaxyTab) for "width, height" , but it always stays at 800x600, that is what I find in my current global device-settings. I also tested to switch with/height related to ori-settings, but found no combination that worked (the "quality"-param works...)

What could be wrong?



Another point close to this:
I would also like to change the preview-format from jpg to NV21, but didn't find this method yet (maybe overlooked?)
Camera.Parameters | Android Developers
The only thing I noticed is, that NV21 is what I find in my device-settings, but I always recieve jpg-format on B4A-side.
So -if not overlooked- I would kindly ask for implementation of this method, if possible and not too extensive.


All other things I used/tested work very well.
Thanks for the good work on this lib, it's very useful !


best regards,

henrik
 

Silentsea

Member
Licensed User
Longtime User
Hi henrik,

i also noticed a little problem by choosing another resolution. But looking at the real cam app at the galaxy I found out that only a few resolutions are supported at this device. Which resolution have you choosen? I'd set the resolution (1600x1200) in Sub Camera1_Ready before the preview method will be fired and it worked nicely.

B4X:
'Setting MP
Camera1.PictureSize(Resolution.width,Resolution.height)

Silentsea
 

henrik

Member
Licensed User
Longtime User
Hi Silentsea,

the "Camera.PictureSize()" works well on my device too.

My problem is related to the preview-size. Here my tab gives three options: 1024x600,800x600,320x240.
When testing again today, I could change between 1024x600 and 800x600 (previewSize) with "camera1.setResolution()" but not to 320x240.
The small resolution is what I need, maybe I always tested in this direction and not upwards. I also make these settings in the "Sub Camera_Ready" before starting the preview. The width/height in "camera1.getPictureOnCurrentFrame()" shows no effect.
Maybe 320x240 is displayed, but not really an option for some reason.

Thanks for checking!

best regards,
henrik
 
Last edited:

Silentsea

Member
Licensed User
Longtime User
Hi XverhelstX,

it's me again, sorry ;). Doing some polishing work I found a little strange behaviour of your lib. In a special case I would like to initialize the cam by clicking an button or icon not by resuming (for performance reasons).

Camera1_Ready will only be fired if the panel of the cam is visible at the point of initializing. But this will result in stupid black screen for at least 2 seconds at my galaxy tab. Not only the panel is black, the hole display! Is it possible to change something that there is no longer this black hole ;). I tried to show up a progress layer after the initialize method but the message queue seams to be blocked until cam is ready or has failed.

Else I have to preload the cam every time as I do at the moment, but this is not very handy and not very performant for me :(.

Silentsea
 

bluedude

Well-Known Member
Licensed User
Longtime User
Hi, nice stuff but wondering if you could add support for saving a rotated image.

When using the orientation it does not rotate the saved picture or am I wrong?
 

mkvidyashankar

Active Member
Licensed User
Longtime User
How to get photo information

hi

thanks for the great library
could you please help me?
How to get the data of photo taken such as date of capture, location etc.,


thanks in advance
regards
 

mkvidyashankar

Active Member
Licensed User
Longtime User
I think it is in the methods SetGPSlatitude, SetGPSLongitude and setGPStimestamp
 

rbsoft

Active Member
Licensed User
Longtime User
Has anybody tried the Advanced Camera Library with a Samsung Galaxy Pad P1000?

Taking pictures with CameraBack works flawless, but I do not get CameraFront to work? Any ideas somebody?

Rolf
 

rbsoft

Active Member
Licensed User
Longtime User
I'll give it a try. Thanks for the quick response!

Rolf
 

GabrielM

Member
Licensed User
Longtime User
Hi Rolf,

I have a Galaxy P1000 here and could try if you need to, though cannot find the example code you guys are testing on, ... I am not into camera related projects :sign0104:

Gabi
 

jur123

Member
Licensed User
Longtime User
Option ISO

Hi,

I would like to fix the sensitivity (ISO) of the camera. How can I get to this property?


THx, Jur
 

rbsoft

Active Member
Licensed User
Longtime User
Hello Tomas,

I tried to version 4.3 but without success. Otherwise absolutely great!


Hello Gabi,

I attached a minimum project based on Tomas' sample for you to try out on your Galaxy Tab. Thanks for offering help.

Rolf
 

Attachments

  • TestCamera.zip
    5.9 KB · Views: 215
Last edited:

GabrielM

Member
Licensed User
Longtime User
Hi Rolf,

no joy unfortunately. All saved pictures be it Front or Back button clicked will save always the back camera view. Have tried to add 2 cameras, on 2 panels, etc, still no front camera on screen.

ps: this Galaxy Tab I am using is a P1000XXJPZ with 2.3.3 Gingerbread firmware.

Cheers,
Gabi.
 
Last edited:

rbsoft

Active Member
Licensed User
Longtime User
Too bad, but thank you anyway Gabi.

Rolf
 
Top