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

NeoTechni

Well-Known Member
Licensed User
Longtime User
Xperia Play

Dim shouldbe As String
shouldbe = "SEPIA"
cam.setColourEffect = Shouldbe
Msgbox("Is: " & cam.getCurrentColourEffect & CRLF & "Supported: " & cam.getSupportedColourEffect, "Should be: '" & shouldbe & "' length=" & shouldbe.Length )
 

cooperlegend

Active Member
Licensed User
Longtime User
Hi, Thanks for the library, I downloaded so that I could get the preview in the correct portrait orientation....

Unfortunately I am getting an error saying that I have a java,lang,NullPointerException when using

cameraRear.Initialize(panelPicture, "CameraRear")
cameraRear.OriPortrait()

in Activity_Resume

Please let me know what I am doing wrong! :)

Cheers
 

cooperlegend

Active Member
Licensed User
Longtime User
Hi, I am on 2.3.3 SGSII

I just moved this line of code from the Activity_Resume to Sub CameraRear_Ready and it is now working :)

Was this the likely cause?

Cheers
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
Question for library developers:

I'm adding a video recorder to my Advanced Camera Library.
But I receive an error here:

B4X:
m_recorder.setPreviewDisplay(sv.getHolder());
The method setPreviewDisplay(Surface) in the type MediaRecorder is not applicable for the arguments (SurfaceHolder)

Auto fix does this: (Surface) sv.getHolder()

but that gives me an error.

What should be the right surface/ holder for it?

XverhelstX
 
Last edited:

rkmoray

Active Member
Licensed User
Longtime User
camara issues

I have 2 issues with the advanced camara dll.
1) the preview is always sideways
2) I cannot get the setzoom to work.
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hey Library developers,

I seem to be stuck with the library at the moment.

I show with an inputlist all available colour effects that the device supports but at the end, the colour effect is not active.

here is my code
B4X:
Sub mnuList_Click
'Declare the variables.
Dim strColourEffect As String
Dim strSelectedItem As String
Dim arrayColourEffects() As String
Dim List1 As List

strColourEffect = camera1.SupportedColourEffect 'Gets all the supported effects from the device
strColourEffect = strColourEffect.SubString2(1,strColourEffect.Length-1) ' Removes the '[' and ']' at the beginning and the end of the string
arrayColourEffects = Regex.Split(", ",strColourEffect) ' Splits all the items with ', ' (space included) and puts it in an arrayDim List1 As List
      List1.Initialize
      For i = 0 To arrayColourEffects.Length-1 ' adds the items to the list. (.Length shows how many items there are)
       List1.Add(arrayColourEffects(i)) 'Add the items
      Next
      
      Dim reslist As Int
      reslist = InputList(List1, "Select Colour Effect.", -1) 'show list with the items.
      For i = 0 To arrayColourEffects.Length-1 ' works with the items
          If reslist = i Then
         strSelectedItem = list1.Get(i)
         If strSelectedItem.ToUpperCase = "SEPIA" Then
         Msgbox(strSelectedItem,strSelectedItem.Length) 'Displays the item. 
         End If
         camera1.ColourEffect = strSelectedItem.ToUpperCase 'Sets the value. Uppercase it to work with the Advanced Camera Library.
         End If
      Next
End Sub

At the end: camera1.ColourEffect = strSelectedItem.ToUpperCase, doesn't show the colour effect SEPIA even WHEN the msgbox above it displays?

here is the Java code:

B4X:
/**
    * Sets the color effect of a picture. The following effects are: AQUA,
    * BLACKBOARD, MONO, NEGATIVE, NONE, POSTERIZE, SEPIA, SOLARIZE, WHITEBOARD.
    * For example: Camera1.setColourEffect = "SEPIA"
    */
   public void setColourEffect(String Effect) {
      Camera.Parameters params = c.getParameters();
      if (Effect == "AQUA") {
         params.setColorEffect(Camera.Parameters.EFFECT_AQUA);
         c.setParameters(params);
      }
      if (Effect == "BLACKBOARD") {
         params.setColorEffect(Camera.Parameters.EFFECT_BLACKBOARD);
         c.setParameters(params);
      }
      if (Effect == "MONO") {
         params.setColorEffect(Camera.Parameters.EFFECT_MONO);
         c.setParameters(params);
      }
      if (Effect == "NEGATIVE") {
         params.setColorEffect(Camera.Parameters.EFFECT_NEGATIVE);
         c.setParameters(params);
      }
      if (Effect == "NONE") {
         params.setColorEffect(Camera.Parameters.EFFECT_NONE);
         c.setParameters(params);
      }
      if (Effect == "POSTERIZE") {
         params.setColorEffect(Camera.Parameters.EFFECT_POSTERIZE);
         c.setParameters(params);
      }
      if (Effect == "SEPIA") {
         params.setColorEffect(Camera.Parameters.EFFECT_SEPIA);
         c.setParameters(params);
      }
      if (Effect == "SOLARIZE") {
         params.setColorEffect(Camera.Parameters.EFFECT_SOLARIZE);
         c.setParameters(params);
      }
      if (Effect == "WHITEBOARD") {
         params.setColorEffect(Camera.Parameters.EFFECT_WHITEBOARD);
         c.setParameters(params);
      }
      if (Effect == "sepia") {
         params.setColorEffect(Camera.Parameters.EFFECT_SEPIA);
         c.setParameters(params);
      }
   }

It seemed to be that NeoTechni also struggled with this.
Is this string related or something?

Thanks in advance,

XverhelstX
 
Last edited:

agraham

Expert
Licensed User
Longtime User
You've fallen into a Java trap that I fell into often coming to Java from C#

Effect == "AQUA"

isn't doing what you think. If you had put some logs in your Java code you would have seen that the condition never succeeds because the == is comparing the string instances by their identity and not by their contents. Sometimes == works because the instances are the same object but in this case you are comparing a string generated in the library to a string instance passed in from Basi4android code. You need

Effect.Equals("AQUA")
 

Silentsea

Member
Licensed User
Longtime User
Flash?

Hi XverhelstX,

i've testet your extending libary :). Unfortunately the flash mode setting will not work. I tried the examples you have postet on a samsung galaxy tab (7'') with 2.2.

Camera1.getSupportedFlashMode gives me: on, off, auto and torch; but Camera1.FlashOn will not work :(.

Thanks in advance.
 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
Wich galaxy??? there are a few models out there, The S, The new S2, the Mini, The Tab... some, like the S, do not have built-in Flash!
 

Silentsea

Member
Licensed User
Longtime User
Sry, the tab, see my edited post.

Camera1.getSupportedFlashMode gets the result, thats because I'm wondering.

Flash is working by builtin cam api ;).

Another question for me is, how to show the user a waiting animation, for example with the gif lib, but the ui thread is blocked by loading the cam?
 
Last edited:

Silentsea

Member
Licensed User
Longtime User
I tried some other features of your lib, still waiting on feedback on the flash question for my samsung galaxy tab.

For Example, setting picture size. Im my scenario the cam supports 0.4Mp, W0.6, W1.5, 2M, W2.4M, 3.2M

I found out that your lib doesn't support the "w" formats. I can only switch by setting picture size to the next full size. 1600 x 960 will not be possible, i have to choose 1600x 1200.

Only to note :).
 

francoisg

Active Member
Licensed User
Longtime User
Hi,
I tried the following code but it does not seem to work for some reason (device: Motorola MB525) - does nothing. MaxZoom is returned as 5, but setting it to any value does nothing at all. Obviously I am doing something wrong ...

Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
Select KeyCode
Case KeyCodes.KEYCODE_VOLUME_DOWN:
maxZoom = cam.getMaxZoom
If CamZoom < maxZoom Then
CamZoom = CamZoom + 1
cam.setZoom = CamZoom
End If
Return True
Case KeyCodes.KEYCODE_VOLUME_UP:
If CamZoom > 0 Then
CamZoom = CamZoom - 1
cam.setZoom = CamZoom
End If
Return True
End Select
End Sub
 

alfcen

Well-Known Member
Licensed User
Longtime User
Hi XverhelstX

The ZIP in the first post appears to contain Ver 2.00 i/o 2.01
 
Top