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

vb1992

Well-Known Member
Licensed User
Longtime User
What is the best ACL demo project to test with?
thanks..



Edit:

ok I think it found it in the 1st post zip file: PictureTaken2Example4.4

thanks
 
Last edited:

kanaida

Active Member
Licensed User
Longtime User
camera stolen :) whoops!

Hey man great lib, It's amazingly easy to use and has a nice set of features, however i'm running into a slight bug of sorts.
I declared a panel but didn't initialize it, then I called:

B4X:
camera1.Initialize(plnCamera, "Camera1")

It failed to initialize with some java null exception, wich I expected. However, it never released the camera again lol...

So any camera app that I start, my own, built in, or otherwise can no longer preview the shot or access the camera, probably until I shut down...
:sign0148: lol... any way you could check if the panel is null first and throw your own exception instead so this doesn't happen? :) thanks!
 

vb1992

Well-Known Member
Licensed User
Longtime User
for those who wanted to turn the flash on

use this code:


B4X:
' must have loaded ACL Version 4.40 library
Sub Process_Globals
End Sub

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

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
    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.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


Works fine on a Galaxy Tab 10.1
 
Last edited:

chfajardo

Member
Licensed User
Longtime User
nullPointerException when reading Data()

Hello, XverhelstX!

I´m having some problems.
In the emulator, everything goes well, but when i run in my tablet, every time i try this, i get the nullPointerException and no image is saved:

Sub Camera1_PictureTaken (Data() As Byte)
Dim dir As String
Dim arquivo As String
Dim out As OutputStream
camera1.StartPreview
dir = File.DirDefaultExternal
arquivo = nome_arquivo.Text
If(Data.Length>0) Then
If(arquivo<>"") Then
out = File.OpenOutput(dir, arquivo & ".jpg", False)
out.WriteBytes(Data, 0, Data.Length)
out.Close
ToastMessageShow("Image saved: " & arquivo & ".jpg (" & Data.Length & " Bytes)", True)
Else
Msgbox("Enter the image name!","ERROR")
End If
panel_camera1.Visible = False
camera1.Release
End If
End Sub

My tablet is a Coby Kyros MID7024.

Thanks in advance.
 

susu

Well-Known Member
Licensed User
Longtime User
On my HTC phone the flash turns on. But on Samsung Galaxy Tab 7.0 it didn't.
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
I updated the Camera library to 4.5.

Flashlight related errors are dealt with the hardware of the manufacturers.
Often I find that Motorola and Samsung says they have Torch, but it actually doesn't work. I tried to find some hack arounds, but I am not in the capacity of testing them:

try ToggleFlashlight
(however when toggeling off your Flashlight on samsung, you will have to reinitialize your camera as some samsung devices doesn't shut down the flashlight.) (hack around)


I updated the zoom, it should work now . (I also can't test it because my phones don't have zooming enabled):
3 functions available:
SetZoom
setZoomIn
setZoomOut

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)

Here are B4A functions to convert the return parameter strings to and from B4A Maps. (copyright Canalrun)

B4X:
Sub StrToMap(str As String, mp As Map)
Dim i, j, k As Int
Dim t, u, mk, mv As String

If (mp.IsInitialized = False) Then mp.Initialize
mp.Clear
t = str
i = 0

Do While (i < str.Length)
t = t.SubString(i)

j = t.IndexOf(";")
If (j >= 0) Then
i = j + 1
u = t.SubString2(0, j)
u = u.Trim
Else
i = str.Length + 1
u = t.Trim
End If

j = u.IndexOf("=")
If (j >= 0) Then
mk = u.SubString2(0, j)
mk = mk.Trim
mv = u.SubString(j+1)
mv = mv.Trim
End If

If ((mk.Length > 0) AND (mv.Length > 0)) Then
mp.Put(mk, mv)
End If
Loop
End Sub

Sub MapToStr(mp As Map) As String
Dim i As Int
Dim s, t, k, v As String

t = ""

For i=0 To mp.Size-1
s = mp.GetKeyAt(i)
v = mp.GetValueAt(i)

s = Sprintf("%s=%s", Array As Object(s, v))
If (t.Length = 0) Then
t = s
Else
t = sprintf("%s;%s", Array As Object(t, s))
End If
Next

Return(t)
End Sub

I also added to enable Motorola LED (don't know what is it though :BangHead:)

Check it out and tell me if it works,

Tomas
 
Last edited:

vb1992

Well-Known Member
Licensed User
Longtime User
susu
What if you added a start preview below?
B4X:
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
 
Last edited:

ostau

Member
Licensed User
Longtime User
Orientation problem on Samsung Tab 7

Hallo,

I use the Samsung Tab 7 (P1000) and tried the sample in ACL 4.4 (I have to make pictures from wounds, so I cann´t use the simple Camera-Lib due to the missing focus ability).
I always get a preview in the imgView which is rotated by 90 degrees. Changing the Orientation with oriPortrait or oriLandscape doesn´t change anything. When I rotate the tab, the rpeview also rotates. Crazy.

Another problem is, when I try use FlashOn the app crashes.

I also tried to install ACL4.5, but when I try to activate it, I get an Error:
An error occurred. Error parsinf libraries. xvs.ACL.Base64.decode already exists.
I´m wondring, why the ACL 4.5 is so much smaller than ACL 4.4?

Can anybody help me out?

Kind regards, Oskar
 

ostau

Member
Licensed User
Longtime User
Hallo,

I use the Samsung Tab 7 (P1000) and tried the sample in ACL 4.4 (I have to make pictures from wounds, so I cann´t use the simple Camera-Lib due to the missing focus ability). ....


Shame on me. I found the solution in a previous post.
For all others, who are seearching:
1. Tick the phone lib.

in Activity_Resume after camMain.Initialize(pnlCamera, "camMain")

Dim p As Phone
p.SetScreenOrientation(0)

Aadpot your layout for landscape and voila.
It also works, when your app doesn´t support landscape orientation.

Regards, Oskar
 

francoisg

Active Member
Licensed User
Longtime User
Hi,
what type does the SupportedPictureSize function return (I see it is a list but what type is contained in the list???) - maybe I'm just missing some vital part of the documentation but I can;t seem to find any information on this!

Greetings from South Africa!!
 

francoisg

Active Member
Licensed User
Longtime User
In case anyone else is wondering, I used the reflection lib to get to the info from the SupportedPictureSize function ...

code (returns info for 1'st resolution reported):
Dim r As Reflector : r.Target = cam.SupportedPictureSize.Get(0)
Width = r.GetField("width")
Height = r.GetField("height")
 

dagofo

Member
Licensed User
Longtime User
Same error!!

I also tried to install ACL4.5, but when I try to activate it, I get an Error:
An error occurred. Error parsing libraries. xvs.ACL.Base64.decode already exists.

There is a Solution???

Thanks
 

francoisg

Active Member
Licensed User
Longtime User
Same error here - on B4A version 1.60 ... and version 1.7 ... any answers on this???
 
Last edited:

oymyakon

Member
Licensed User
Longtime User
picture size

camera1.picturesize keeps giving me an error i have ensured it is prior to startpreview any ideas?

Paul.
 

droman

Member
Licensed User
Longtime User
Is possible make a photo from widget? (without GUI).




Sorry for my english
 

andrewtheart

Member
Licensed User
Longtime User
Getting an interesting error: B4a 1.6 and library version 4.45

Rc56o.png


EDIT: same issue if I uncheck "Camera" from the Referenced Libraries list. But using library version 4.4, the issue goes away.
 
Last edited:
Top