B4A Library VBFrontCam (Front Camera Library) 1.0

VBFrontCam (Front Camera Library) 1.3

Releasing VBFrontCam 2.0

  • CameraFront
    Events:
    • Ready (Success As Boolean)
    • PictureTaken (Data) As Byte)
    Permissions:
    • android.permission.CAMERA
    Methods:
    • CameraCount As Int
      returns an int of how many cameras you have example: 0,1,2
    • Initialize (Panel As ViewGroup, EventName As String)
      Initializes the camera.
      Panel - The preview images will be displayed on the panel.
      EventName - Events subs prefix.
      The Ready event will be raised when the camera has finished opening.
    • Older1a
      Try front camera on Android version 2.2 and under
      Behind the scenes we use: p.set("camera-id", 1);
    • Older1b
      Try front camera on Android version 2.2 and under
      Behind the scenes we use: p.set("camera_id", 1);
    • Older2a
      Try front camera on Android version 2.2 and under
      Behind the scenes we use: p.set("camera_id", 2);
    • Older2b
      Try front camera on Android version 2.2 and under
      Behind the scenes we use: p.set("camera-id", 2);
    • Release
      Releases the camera object and allows other processes to access the camera.
    • Rotate180
      rotates 180
    • Rotate270
      rotates 270
    • Rotate90
      rotates 90
    • SetBlackWhite
      SetBlackWhite
    • SetEffectNone
      Set Effects Color back to normal
    • SetExposureStong2
      Front camera is a little dark, so this helps
      Boost Exposure Level to 2, should work on most phones
    • SetExposureStong4
      Front camera is a little dark, so this helps
      Boost Exposure Level to 4, might not work on all phones
    • SetExposureStong6
      Front camera is a little dark, so this helps
      Boost Exposure Level to 6, might not work on all phones
    • SetSepia
      EFFECT_SEPIA
    • SetZoomIn (zlevel As Int)
      SetZoomIn() No need to pass it anything
    • SetZoomOut
      SetZoomOut() No need to pass it anything
    • StartPreview
      Starts displaying the preview images.
    • StopPreview
      Stops displaying the preview images.
    • TakePicture
      Takes a picture. When the picture is ready, the PictureTaken event will be raised.
      The preview images are stopped after calling this method. You can call StartPreview to restart the preview images.

Also includes:

EFFECTS: None, Sepia, Black and White
ZOOM: zoomin(int as level)
EXPOSURE: Compensation Boosts
( I Find is needed on front cams since they seem darker )

Some phones won't support effects, zoom, or Exposure,
but it's there if you need it.


Attached is an example program, please test and give feedback.


Thanks in Advance

Vb1992

Library Revision History:

old...... Library is version 1.0 - June 16th, 2012
old...... Library is version 1.1 - June 18th, 2012 (Fixed library to deal with tablets with only 1 camera) (added zoom in level parameter)
old...... Library is version 1.2 - June 18th, 2012 (Fixed library to deal with front cameras before pre-gingerbread 2.3) Camera.Older2b
old...... Library is version 1.3 - June 23rd, 2012 (Fixed library to deal with rotations) Rotate90() Rotate180() Rotate270()

Current Library is version 2.0 - August 1st, 2012 (Fixed library to deal with front camera on Samsung and ICS)

.
.
.
.
.
.
 

Attachments

  • frontcam-example-project.zip
    8.8 KB · Views: 1,012
  • FrontCameExamplePreGingerBread2.3.zip
    9 KB · Views: 709
  • VBFrontCam1.3.zip
    7.4 KB · Views: 577
  • VBFrontcam2.0.zip
    7.6 KB · Views: 979
Last edited:

susu

Well-Known Member
Licensed User
Longtime User
Thank you so much! It works great on my HTC Sensation XE. Could you please make it record video?
 

peacemaker

Expert
Licensed User
Longtime User
Does not work on A10 AllWinner Android 4.0.3 tablet, but camera exists:

Error log:

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
There is 1 cameras attached to this device
CAMERA_FACING_FRONT is # 1
FOR loop CamIDX = 0 and CameraCount = 1
If cameraInfo.facing(1) = camIdx(0)
main_fc_ready (B4A line: 94)
FC.StartPreview

java.lang.NullPointerException
at vb.front.cam.fronty.StartPreview(fronty.java:178)
at vb.front.camera.main._fc_ready(main.java:481)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:145)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:133)
 
Last edited:

susu

Well-Known Member
Licensed User
Longtime User
I tested on my tablet Transformer TF300 and it worked ! :D
 

peacemaker

Expert
Licensed User
Longtime User
Does this tablet only have one camera
and it's on the front?

Exactly. (Also: lib for the back camera does not work with this tablet, but works with LG P500 phone OK).
There is 1 cameras attached to this device
CAMERA_FACING_FRONT is # 1
FOR loop CamIDX = 0 and CameraCount = 1
If cameraInfo.facing(1) = camIdx(0)
Log shows something about the camera.

Is it your lib logging this ?
 
Last edited:

vb1992

Well-Known Member
Licensed User
Longtime User
With Android 2.3, you can use the android.hardware.Camera class to get the number of cameras, info about the camera, and get a reference to a specific Camera.

.CAMERA_FACING_FRONT

No Front Camera API for this, through Android 2.2
I been trying to test setting different parameters for 2.2 and below

B4X:
 Camera cam = Camera.open();
    cam.setDisplayOrientation(90);
    cam.setPreviewDisplay(holder);

    Camera.Parameters para = cam.getParameters();
    para.set("camera-id", 2);
    cam.setParameters(p);
 

vb1992

Well-Known Member
Licensed User
Longtime User

vb1992

Well-Known Member
Licensed User
Longtime User
Library update

Current Library is version 1.1 - June 18th, 2012
(Fixed library to deal with tablets with only 1 camera)
(added zoom in level parameter)

B4X:
Try

FC.SetZoomIn(4)
 
Catch
msgbox("Does not support ZoomIn(4)","Warning")
End Try
 

nad

Active Member
Licensed User
Longtime User
Wonderful lib, exactly what i needed.

I have a small problem though. It seems the fc.rotate90 is not working for me (i have a galaxy s3)

So i can only see my face as portrait when on landscape and the opposite so cannot add and see correctly any view.

maybe i am not using correctly using the fc.rotate90

B4X:
Sub fc_Ready (Success As Boolean)
   
   Try
      

      FC.StartPreview
      
      

   Catch
   
      Msgbox("Cannot start front camera preview","Problem")
      
   End Try
   Try
      FC.Rotate90
      
   Catch
   End Try
   
End Sub

Thanks a lot :) !
 

nad

Active Member
Licensed User
Longtime User
I have to try that.
I tried configuring the activity to landscape or to portrait, not both

Thanks!
 

nad

Active Member
Licensed User
Longtime User
Nope, it does not fix it, i have also tried with p.setscreenorientation(-1) and (0) but no luck.

FC.Rotate90 is not working for me in either Samsung Galaxy SII, SIII or HTC Desire HD

I can only see the preview in portrait if i set the project options to landscape and when set in portrait i see the preview en landscape, so if i want to add a view it will always be seen as rotated 90º to the viewer.

Do i need to do something specific to have the rotation working?

Cheers and thanks for your support!
 

vb1992

Well-Known Member
Licensed User
Longtime User
test out this version of the library
it has a few rotations

Rotate90()
Rotate180()
Rotate270()

You will have to test both ways, with Starting and Stopping preview when you make
the rotate setting


also here is code to get the rotation

B4X:
Dim r As Reflector
Dim rotation As Int
r.Target = r.GetActivity
r.Target = r.RunMethod("getWindowManager")
r.Target = r.RunMethod("getDefaultDisplay")
rotation = r.RunMethod("getRotation")
Msgbox("rotation=" & rotation, "info")
 

Attachments

  • VBFrontCam1.3.zip
    7.4 KB · Views: 226

nad

Active Member
Licensed User
Longtime User
Woot!,
that fixed it ! now it runs perfectly.
You are great :)

Cheers and thanks a lot

:)
 
Top