B4A Library Advanced Camera Library V1.00

Discussion in 'Additional libraries, classes and official updates' started by XverhelstX, May 25, 2011.

  1. XverhelstX

    XverhelstX Well-Known Member Licensed User

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

    Hello everyone!

    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


    [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

    2) Camera's

    3) Orientation

    4) Pictures

    5) Antibanding

    6) Colour Effects

    7) Focus Mode

    8) Scene Mode

    9) White Balance

    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!


    Full example:

    '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.AddMenuItem("Take Picture","mnuTakePicture")
    activity.AddMenuItem("Set Effect","mnuSetEffect")
    activity.AddMenuItem("Flash On","mnuFlashOn")
    activity.AddMenuItem("Focus Mode","mnuFocusMode")
    End Sub

    Sub Activity_Resume
    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
    End Sub

    Sub mnuFlashOn_Click

    End Sub

    Sub mnuSetEffect_Click

    Camera1.setEffect = 

    End Sub

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

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

    End Sub

    Sub mnuTakePicture_Click
    End Sub

    Sub mnuFocusMode_Click
       camera1.setFocusMode = 
    End Sub

    Attached Files:

    Last edited: Dec 16, 2011
  2. Merlot2309

    Merlot2309 Active Member Licensed User


    Will test and use it asap.
    Glad that you found B4A :sign0188:


  3. NeoTechni

    NeoTechni Well-Known Member Licensed User


    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.
  4. XverhelstX

    XverhelstX Well-Known Member Licensed 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.


    Sent from my SE Xperia Play using Tapatalk.
  5. ZJP

    ZJP Active Member Licensed User

    Do not forget
    The parameters must be modified before :
    Thx :sign0098:

    Last edited: May 26, 2011
  6. susu

    susu Well-Known Member Licensed User

    Thank you XverhelstX! You always create fantastic libraries.
  7. Erel

    Erel Administrator Staff Member Licensed User

    Great work XverhelstX.
    I recommend you to change the name of this library to AdvancedCamera. The space can do all kinds of strange problems.
  8. XverhelstX

    XverhelstX Well-Known Member Licensed 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.

    Last edited: May 26, 2011
  9. max19871

    max19871 Member Licensed 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?
  10. Shay

    Shay Well-Known Member Licensed User


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

    Sub Camera1_Ready (Success As Boolean)
    If success Then
    ToastMessageShow("Cannot open camera.", True)
    End If
    End Sub
  11. Ratters

    Ratters Member Licensed 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?



    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: May 28, 2011
  12. Ratters

    Ratters Member Licensed 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 :)
  13. Ratters

    Ratters Member Licensed 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)

  14. Shay

    Shay Well-Known Member Licensed User


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

    Sub Camera1_Ready (Success As Boolean)
    If success Then
    ToastMessageShow("Cannot open camera.", True)
    End If
    End Sub
  15. Ratters

    Ratters Member Licensed User

    Hi Shay,

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

  16. Shay

    Shay Well-Known Member Licensed User

    Erel any input?
  17. Erel

    Erel Administrator Staff Member Licensed User

    Sorry but I'm not the author of this library and not familiar with its implementation.
  18. alfcen

    alfcen Well-Known Member Licensed 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
  19. XverhelstX

    XverhelstX Well-Known Member Licensed 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:
    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:
    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:
    camera1.setZoom = 4

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

    Thank you, feedback will be really much appreciated!

  20. agraham

    agraham Expert Licensed 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
    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") {
        if (Antibanding == "ANTIBANDING_60HZ") {
        if (Antibanding == "ANTIBANDING_AUTO") {
        if (Antibanding == "ANTIBANDING_OFF") {
    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.

Share This Page