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

XverhelstX

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

I don't know why I did this ;p.
The output seems good that people can see whether they are using to get or change the variable.
Personally, I prefer this method because it's easier to see.

But if you guys would like it to change
from setXXX and getXXX to just XXX, tell me. :)

I will also add the version to the ZIP.

Thx for your feedback Agraham.

Tomas

I will also
 

Ratters

Member
Licensed User
Longtime User
Advancedcamera V2.0 - Fantastic !

Hi XverhelstX,

fantastic news...

I really appreciate your time, I know myself what its like to juggle events around ;)

Excellent library...

If I have any issues, I'll post it back on this thread.

Cheers...

Robbie
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hey Robbie,

Thank you :)

Although, I have a question on your previous answer. :)o)

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 :)

So here you mean that the camera on your screen side (facing to you) is the back camera?
Then it's a bug in the library and I have to switch it because the front camera is on the screen side.

Tomas
 

Ratters

Member
Licensed User
Longtime User
Hi XverhelstX,

Yep, thats right, I found this by trial and error testing... I've only tried it on a Samsung Galaxy S phone, I have no other to try, sorry.

I haven't tried it yet on the new release... 2 mins :)

Robbie
 

Ratters

Member
Licensed User
Longtime User
Hi XverhelstX,

camera1.CameraBack uses the camera on the screen side on the Galaxy S.

Hope this helps.

Cheers

Robbie
 

Ratters

Member
Licensed User
Longtime User
And as if by magic....

That's great Tomas, tried and tested... That was quick :)

camera1.CameraFront is now screen side.

Robbie
 

Ratters

Member
Licensed User
Longtime User
Sorry Tomas,
may have found another bug,

Using;

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


I am unable to capture the outputstream using the front camera. The screen appears green and the camera sound is heard but that's it - it just displays a constant green screen in the relating panel.
 

NJDude

Expert
Licensed User
Longtime User
Do the "effects" work?, I've tried the sample code and I get an error on SEPIA, no such member.

NOTE: I noticed the posted sample is a little "old" it seems things were changed on version 2, also, there is a typo on the FLASH section, I see that the instruction to turn the flash off is FlashOn instead of FlashOff.
 
Last edited:

XverhelstX

Well-Known Member
Licensed User
Longtime User
U should first check with getSupportedeffect or something.
It returns a list with the supported effects. See page 2 for mor information on this topic.

XverhelstX

Sent from my SE Xperia Play using Tapatalk.

Edit: yeah, i will edit the topic later. First take some sleep.
 
Last edited:

Omar

Member
Licensed User
Longtime User
Dear XverhelstX

Thank you very much for this excellent library, I am encountering an error with the basic command:

Camera1.FlashOn()

Camera1 has been dim'd as an AdvancedCamera and the library is loaded but I keep getting the java.lang.NullPointerException error when compiling on the above code.

Could you please advise what am I doing wrong?
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
On what android version are u testing it on?
and what android smartphone u test it on?
The flashlight is supported since: API Level 5; Android 2.0).

Did you also do:
B4X:
dim Camera1 as AdvancedCamera
Camera1.FlashOn()

XverhelstX
 

Omar

Member
Licensed User
Longtime User
Hi XverhelstX,

I am using the HTC Desire HD. For some reason it keeps crashing on:

Camera1.FlashOn()


I am using Android 2.2.1

Also I tried only using:

dim Camera1 as AdvancedCamera
Camera1.FlashOn()

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

Thanks for your help to look into this.
 
Last edited:

Omar

Member
Licensed User
Longtime User
Thank you for your quick help.

I tried the code:

Msgbox(camera1.getSupportedFlashMode(),"")

But I get the error message: Array Expected.

Not sure what is wrong with this.



Does any other code work with it?

So yes, could you do:

B4X:
camera1.getSupportedFlashMode()

and show the list of what you receive?

Thanks,

XverhelstX
 

Omar

Member
Licensed User
Longtime User
Thanks for the clarification. I will try the code shortly and update on what I receive back. I will get back to you after a little while.

Thank you


You have to use:

B4X:
   Msgbox(Camera1.getSupportedFlashMode,"")

this is without the () after getSupportedFlashMode.

XverhelstX
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
ok, the problem will probably be related to the device as some manufacturers have different settings. I have to go now, but I will update the library tomorrow with some more stuff and I think (not sure) I can fix it.

XverhelstX
 
Top