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,075
  • ACL4.5.zip
    33.5 KB · Views: 1,489
  • ACL4.6.zip
    359.4 KB · Views: 5,009
Last edited:

XverhelstX

Well-Known Member
Licensed User
Longtime User
AdvancedCameraLibrary Update

Updated to ACL 4.6

- Fixed ACL.ACL.base64 bug
- Added reconnect.
- Zoom functions (please test this.)
- More camera light things have been added. (try them out, I only have 1 device to test on.)
- Front camera gingerbread update
- CurrentPictureSizeHeight - CurrentPictureSizeWidth (proper values) ( CurrentPictureSize deprecated)
- SupportedPictureSizeHeight - SupportedPictureSizeWidth - SupportedPictureSize ( proper values)
- rotateBitmap - rotoateBitmap2: be able to rotate a bitmap quickly after taken a picture. (Bitmap parameter of Bytearray param.)
- Record camera functions removed - See Erel's RecordVideoView
- and some more functions

From 4.5:

Thanks to Canalrun, you can now read, and write strings and integers to the camera! With:

"Read Camera Parameter Key" (rCPKey)
"Write Integer Camera Parameter Key" (wiCPKey)
"Write String Camera Parameter Key" (wsCPKey)
"get Parameter String" (ParmStr)
"set parameter String" (ParmStr)

See more info here: http://www.b4x.com/forum/additional...nced-camera-library-v1-00-a-15.html#post71782

Note that I may now within 1-3 weeks completely rewrite the ACL camera again. (For the 3rd time). This is to make programming much easier, better syntaxis, more declarations, e.g (dim face as FaceRecognition, etc) all in the ACL.

If you have some more questions, found bugs, comments, please post them here.

Tomas
 

dagofo

Member
Licensed User
Longtime User
Hello.

First, thanks for your updates.

One question. ¿How can we control camera Brightness?

We have Samsung Galaxy mini for our peoble and this phone does not have flash. We only can "play" with Brightness to make better photos.

Thanks in advance
 

mkvidyashankar

Active Member
Licensed User
Longtime User
zoomin and zoomout Advanced Camera library

zoomin and zoomout is not working in Galaxy Tab but is working in LG P500 and Flashon is working sometimes, flashtorch is not working in Galaxy Tab.

SupportedPictureSizeHeight - SupportedPictureSizeWidth - SupportedPictureSize ( proper values) is working properly:sign0142:
 
Last edited:

COBRASoft

Active Member
Licensed User
Longtime User
Hi,

I discovered a big problem with 'TakePicture2'. The size is much bigger than 'TakePicture' and takes a lot longer to process. I use 90 degrees.

After some pictures, I get an out of memory exception when taking portrait pictures and save them with 'TakePicture2'.

In Landscape mode and 'TakePicture', I have no problems and no exceptions.

Any idea?

Greetings,
Sigurd
 

vb1992

Well-Known Member
Licensed User
Longtime User
FlashTorch works in Galaxy tab


B4X:
Sub Globals
     Dim camera1 As AdvancedCamera
    Dim Panel1 As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
'
'  Just add a Panel to the layout and save it as Menu
'
'
    Activity.LoadLayout("Menu")
     activity.AddMenuItem("Flash On","mnuFlashOn")
 End Sub


'
' A C T I V I T Y - R E S U ME
'
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.StartPreview
    camera1.FlashTorch() ' Gives the FLASH LIGHT always on effect

    'camera1.flashon()  ' gives a normal flash when taking a photo
'un comment it if you want this one

End Sub
 

mcmanu

Active Member
Licensed User
Longtime User
Rotating the Panel

Hi,

Thanks for this great Library.

I have a Problem: I need to rotate the Panel
My application is not supporting p.setscreenorientation.Is there a way to rotate the panel? that i can use the camera in portrait orientation? Its Strange i tested it again an when the camera first starts, there is a black screen, then when i press the take picture button, the orientation works fine o_O

My code -->
Sub Camera1_Ready (Success As Boolean)

If success Then
camera1.OriPortrait
Camera1.StartPreview
button5.Enabled = True
Else
ToastMessageShow("Kamera konnte nicht geöffnet werden.", True)
End If
End Sub

Sub Camera1_PictureTaken (Data() As Byte)
' camera1.OriPortrait
camera1.StartPreview

Dim out As OutputStream
out = File.OpenOutput(File.DirRootExternal, "1.jpg", False)
out.WriteBytes(data, 0, data.Length)
out.Close
ToastMessageShow("Dein Bild wurde gespeichert: " & File.Combine(File.DirRootExternal, "1.jpg"), True)

button5.Enabled = True
End Sub

'Kamera auslösen
Sub Button5_Click
button5.Enabled = False
camera1.TakePicture
label4.Text = "Dein bild wurde gespeichert"
TTS1.Speak(label4.Text, True)
End Sub
 
Last edited:

gehrlekrona

Member
Licensed User
Longtime User
Advanced Camera, help needed

I have a "main app" with one layout and then I added another layout ("1") for the camera that I grabbed from another camera project.

If I compile and run the camera sample it works and it show up in the Panel1 window. My problem is that I have this code:

result = Msgbox2("Want to take picture and upload?", "Take Picture", "Yes", "", "No",Null)

If result = DialogResponse.Positive Then

Activity.LoadLayout("1")
Camera1.StartPreview
Camera1.FlashAuto()
Panel1.BringToFront

End If

What I want to do is to take a picture if the user answers Yes but the preview in the Panel1 is not showing up and I can't figure out what to do :(
Any suggestions?
 

gehrlekrona

Member
Licensed User
Longtime User
PictureSize

I can't get PictureSize to work. I am using the AdvancedCamera and the code looks OK but when I use it in my camera I get a java error with parameters.
 

kennemore

New Member
Licensed User
Longtime User
I can't get PictureSize to work. I am using the AdvancedCamera and the code looks OK but when I use it in my camera I get a java error with parameters.

I also get the error when trying to set the picture size. Has anyone found a fix?
 

BobsYourUncle

Member
Licensed User
Longtime User
TakePicture2 Not Working

Hi,

First of all - Nice library! Excellent job!

I am having problems using TakePicture2 with ACL 4.6 - It always hangs!

This works:-
B4X:
camera1.TakePicture

This hangs every time:-
B4X:
camera1.TakePicture2(90)

The shutter sound is made, but then things hang and the PictureTaken event is never fired.

Hope someone can help!

Kind regards,
BobsYourUncle
 

BobsYourUncle

Member
Licensed User
Longtime User
Seem to have solved the problem myself.

When you use Camera1.TakePicture2, it raises

B4X:
Sub Camera1_PictureTaken2 (Data() As Byte)

instead of

B4X:
Sub Camera1_PictureTaken (Data() As Byte)
 

Dirk A

Member
Licensed User
Longtime User
XverhelstX

Hi XverhelstX

I have no experience with B4android.
But we are going to use it.
I want to create a little app that works like a lamp for a GSM Mobile phone.

Is there a procedure in de Advance camera lib to put on the led of the camera constant ON are OFF.
So we can use this as a lamp.

Dirk
 

derez

Expert
Licensed User
Longtime User
Hi Tomas
Thank you for this library, I just checked it today and found a wide world of opportunities !

First problem - I can't get the front camera on my Asus Transformer (3.2) to show or take pictures. The back cam works.
I tried both ways - but no:(

David
 
Last edited:

Molando

Member
Licensed User
Longtime User
rather lost in eclipse with ACL

Hello all,
Hope one of you can help.
Professional programmer by trade, but rather new to eclipse and java (too many years with assembler/C#/Delphi etc). In one of the earlier posts somebody mentioned that he managed to overrided onPreviewFrame.

I am attempting to do the same as would like to get access to the image data as soon as possible in its most raw format, but becoming rather confused.

I attempted with JarPlug on the acl.jar file, with lines like the following:
public void setResolution(int width, int height);
0 getstatic xvs.ACL.ACL.c : android.hardware.Camera [173]
3 invokevirtual android.hardware.Camera.getParameters() : android.hardware.Camera$Parameters [296]
6 astore_3 [params]
7 aload_3 [params]
from the post earlier it felt that the fellow had access to the source.

Would be very greatful if somebody could point me in the right direction to be able to do the override, or access the source.

Which version of eclipse should I be using?
Should I work with JarPlug?
What is the trick of getting to the source, or do I override in a seperate unit, then rebuild this into a new Jar file for use in B4a?
Or do I have this all totally confused, I should go and have a nice cup of tea?

I am after the image data hopefully in RGB format, in some sort of memory dump, rather than it being passed over as a jpeg, or bmp, then having to turn it back to its origional format. If I can access the data with a picture[calculated offset for red component] rather than calling a routiene that poddles off and gets the values slowly, it would also help.

Any ideas?

Regards,
Jonathan/Molando.
 
Last edited:

droman

Member
Licensed User
Longtime User
Android Camera API - Tutorial

In this example, the camera works perfectly in front Galaxy S. It's simple, apparently, and I think that could be implemented in the library .... if the developer wants to clear. This would cease to be problems by the use of the camera.

Thank you.
 

rtesluk

Member
Licensed User
Longtime User
Camera1.SupportedPreviewFpsRange

Mar 5 2012
02:00 Hours

How do you fetch the values from Camera1.SupportedPreviewFpsRange.

This list is different because each element has an integer array of TWO values.

Ray Tesluk
Port Hope, Ontario
Canada
:sign0163:
 
Top