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:

NeoTechni

Well-Known Member
Licensed User
Longtime User
Awesome

Just so we don't have to memorize those strings, I'd suggest a way to obtain them from the lib.

ie: returning a list of them
function PollColorModes() as list

Makes me wish we had an enum type.
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
@merlot, Thanks! I'm glad I've found B4A. ;)

@neo, there is a way with the IDE. Just start typing like camera1. Then select it from the list and the info will be displayed with all functions.

XverhelstX

Sent from my SE Xperia Play using Tapatalk.
 

susu

Well-Known Member
Licensed User
Longtime User
Thank you XverhelstX! You always create fantastic libraries.
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
@ ZJP; Thanks, I will add it to the topic.

@ susu; Thank you ;D, I got a lot of help from other people too.

@ Erel; Name of library has been changed, thanks.

@ All; Added a complete example of the Advanced Camera Library.

XverhelstX
 
Last edited:

max19871

Member
Licensed User
Longtime User
Thanks XverhelstX, as always a great library. :sign0060:

Just a question, if i try to issue a camera1.CameraFront i get a java.lang.NullPointerException, it means that in 2.2 still can't use frontcam?
 

Shay

Well-Known Member
Licensed User
Longtime User
Hi

I cannot make th portrait to work
what am i doing wrong:


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

Ratters

Member
Licensed User
Longtime User
Camera will not initialise....

Hi XverhelstX,

I tried your example but camera fails to come on, it shows a constant black screen and takes a while for the menu to come up when I press it. I have to exit the app via the back button to stop.

I've installed/copied the new AdvancedCamera library in the right folder and tried including the normal camera in the build too (I'm sure you don't have to include it), but it still presents a black screen.

I am using a Samsung Galaxy S to test it but I am still using basic4android V1.30, will I have to upgrade to the newer version of your software?

Thanks

Robbie

BTW. Best wishes to you all for such an excellent product and all the support.

Sorry - the phone was at fault regarding the black screen, I rebooted the phone and it works fine, it must have got itself tied up or something, however, now I'm stuck on getting the orientation and front camera, am I right in thinking the front camera (camera1.CameraFront) is only available on 2.3 version (I'm using 2.2 to build) but the camera1.OriPortrait() still fails to work even when I try it before the startpreview.

Great work :)
 
Last edited:

Ratters

Member
Licensed User
Longtime User
is it back or front ?

Sorted with the camera1.CameraFront, silly me, on the Galaxy S I used the camera1.CameraBack to use the camera on the same side as the screen, I just thought the screen side was the front of the camera, Doh!

Hope this help others...

Robbie :)
 

Ratters

Member
Licensed User
Longtime User
camera1.CameraBack issue - more feedback

Hi all,

I have found an issue with the back camera (screen side) that does not write out via the OutputStream, the file does write to the folder but only writes 0 bytes. I've tried it with various locations on the device but still does not complete. The other camera (camera1.CameraFront) works fine (on Galaxy S).

Tested using;

Dim out As OutputStream
out = File.OpenOutput(File.DirDefaultExternal, "photo.jpg", False)
out.WriteBytes(data, 0, data.Length)
out.Close


Robbie
 

Shay

Well-Known Member
Licensed User
Longtime User
Hi

I cannot make th portrait to work
what am i doing wrong:


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

Ratters

Member
Licensed User
Longtime User
Hi Shay,

I am having the same problem on the main camera... it may be a bug...

Robbie
 

alfcen

Well-Known Member
Licensed User
Longtime User
Hello XverhelstX,

Congratulations on another fantastic job! Works like a charm (Sharp IS03).

My "SkyScanner" application searches the Sun, Moon and planets with the camera and measures positions in various coordinate systems once an object is centered in a finder grid. I have always been missing portrait mode.

Do you think it is possible to set ISO values, too?

Thanks a lot and Cheers
Robert
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
Big Update!!! V2.0

Hello everyone,

First of all, I am very sorry for my late inactivity these last days.
I was kinda busy with a lot of things including school, my own projects, etc, so my apologies. So I wanted to make things good again, I updated the library with a bunch of new things! :D

So here is the list of the update:

1. getCurrent

a. getCurrentAntibanding
b. getCurrentColourEffect
c. getCurrentFlashMode
d. getCurrentFocusMode
e. getCurrentPictureSize
f. getCurrentSceneMode
g. getCurrentWhiteBalance

These codes will give a string about the current state that the camera is using.
For example:
B4X:
Msgbox(camera1.getCurrentSceneMode(),"")
This could give Sepia as output for example.

2. getSupported

a. getSupportedAntibanding
b. getSupportedColourEffect
c. getSupportedFlashMode
d. getSupportedFocusMode
e. getSupportedPictureSize
f. getSupportedSceneMode
g. getSupportedWhiteBalance

These codes will give a list about all the supported states of the device.
For example:
B4X:
Msgbox(camera1.getSUPPORTEDSceneMode(),"")
This could give BEACH,... as output for example.

3. Max, Min and Is

a. getMaxExposureCompensation
b. getMinExposureCompensation
c. getMaxZoom
d. isZoomSupported

4. 3 new set!

a. setExposureCompensation: a technique for adjusting the exposure indicated by a photographic exposure meter,
b. setISOValue Film speed - Wikipedia, the free encyclopedia
c. setZoom

These codes will give a list about all the supported states of the device.
For example:
B4X:
camera1.setZoom = 4


5. Landscape/Portrait mode has been fixed! Also make sure to use:
B4X:
Dim p As Phone
p.SetScreenOrientation(0 or 1)
to let the screen turn with it.


Thank you, feedback will be really much appreciated!

XverhelstX
 

agraham

Expert
Licensed User
Longtime User
I would suggest that you add the library version number to the name of the zip in the first post so that it is clear what version it contains.

Also why are you using getgetXXX and setsetXXX. Doing this you get two differently named properties, one read-pnly and one write-only. If you use say
B4X:
  public String getAntibanding()
  {
    Camera.Parameters params = c.getParameters();
    return params.getAntibanding();
  }

  public void setAntibanding(String Antibanding)
  {
    Camera.Parameters params = c.getParameters();
    if (Antibanding == "ANTIBANDING_50HZ") {
      params.setAntibanding("50hz");
      c.setParameters(params);
    }
    if (Antibanding == "ANTIBANDING_60HZ") {
      params.setAntibanding("60hz");
      c.setParameters(params);
    }
    if (Antibanding == "ANTIBANDING_AUTO") {
      params.setAntibanding("auto");
      c.setParameters(params);
    }
    if (Antibanding == "ANTIBANDING_OFF") {
      params.setAntibanding("off");
      c.setParameters(params);
    }
  }
You will then get a single read-write property called Antibanding.

If you really want to call something "GetSupportedAntibanding" then just upperscase "Get..." and the compiler won't process it as a property.
 
Top