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:

kcdatsteven

Member
Licensed User
Longtime User
VBFrontCam (Front Camera Library) 1.3

Hi all,
i'm using EKEN T01A Boxchip A10 1.5GHz Android 4.03 ICS Cap Tablet.
I've encountered an error whenever i click "take picture" button;

** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = true **
There is 1 cameras attached to this device
CAMERA_FACING_FRONT is # 1
Opening Camer # 1
Front Camera failed to open: Fail to connect to camera service
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **


but when i using samsung galaxy S2, it do not have such problem.

I'm appreciated if someone can give me advise.

Thank you.
 

vb1992

Well-Known Member
Licensed User
Longtime User
Hi,

Have you tried setting these one by one to see
if they enable that camera:

B4X:
   Dim bb As CameraFront

   bb.Older1a

'   bb.Older1b

'   bb.Older2a

'   bb.Older2b
 

kcdatsteven

Member
Licensed User
Longtime User
VBFrontCam (Front Camera Library) 1.3

Hi,
i tried the method one by one, but it displayed as

--------------------------------------------------------------------------
main_button1_click (java line: 300)

java.lang.NullPointerException
at vb.front.cam.fronty.Older1a(fronty.java:483)
at vb.front.camera.main._button1_click(main.java:300)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:136)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:124)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:120)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:49)
at android.view.View.performClick(View.java:3511)
at android.view.View$PerformClick.run(View.java:14109)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException
** Activity (main) Create, isFirst = true **


** Activity (main) Resume **


There is 1 cameras attached to this device
CAMERA_FACING_FRONT is # 1
Opening Camer # 1
Front Camera failed to open: Fail to connect to camera service
main_button1_click (java line: 300)





java.lang.NullPointerException
at vb.front.cam.fronty.Older1b(fronty.java:458)
at vb.front.camera.main._button1_click(main.java:300)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:136)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:124)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:120)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:49)
at android.view.View.performClick(View.java:3511)
at android.view.View$PerformClick.run(View.java:14109)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException
** Activity (main) Create, isFirst = true **


There is 1 cameras attached to this device


CAMERA_FACING_FRONT is # 1


Opening Camer # 1
Front Camera failed to open: Fail to connect to camera service
** Activity (main) Resume **
main_button1_click (java line: 300)



java.lang.NullPointerException
at vb.front.cam.fronty.Older2a(fronty.java:432)
at vb.front.camera.main._button1_click(main.java:300)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:136)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:124)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:120)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:49)
at android.view.View.performClick(View.java:3511)
at android.view.View$PerformClick.run(View.java:14109)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)


at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException
** Activity (main) Create, isFirst = true **


There is 1 cameras attached to this device


CAMERA_FACING_FRONT is # 1
Opening Camer # 1
Front Camera failed to open: Fail to connect to camera service
** Activity (main) Resume **
main_button1_click (java line: 300)





java.lang.NullPointerException
at vb.front.cam.fronty.Older2b(fronty.java:408)
at vb.front.camera.main._button1_click(main.java:300)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:136)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:124)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:120)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:49)
at android.view.View.performClick(View.java:3511)
at android.view.View$PerformClick.run(View.java:14109)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException
main_button1_click (java line: 300)


** Activity (main) Pause, UserClosed = true **


** Activity (main) Create, isFirst = true **


There is 1 cameras attached to this device


CAMERA_FACING_FRONT is # 1
Opening Camer # 1
Front Camera failed to open: Fail to connect to camera service
** Activity (main) Resume **

--------------------------------------------------------------------------

Hi,

Have you tried setting these one by one to see
if they enable that camera:

B4X:
   Dim bb As CameraFront

   bb.Older1a

'   bb.Older1b

'   bb.Older2a

'   bb.Older2b
 

vb1992

Well-Known Member
Licensed User
Longtime User
few questions:

Have you tested this device with another front camera
app on the google play market to make sure it indeed
works?

Are you using the test example from the first post?
or your own version.

How many total cameras does this have?
 

kcdatsteven

Member
Licensed User
Longtime User
Hi,
1. I've tried to download and install 2 camera apps from google play such as Rage Meme Camera and Eye mask Camera, the front camera is working.

2. i'm downloaded this file "frontcam-example-project.zip" from first post.

3. Only one camera which is front camera.

Thank you so much.
 

vb1992

Well-Known Member
Licensed User
Longtime User
Ok, I will look into the library, I am thinking it's the preview size

I set a default size, but I will change it to read your device
parameters.getSupportedPreviewSizes()

And we will see if that fixes it
 

awama

Active Member
Licensed User
Longtime User
Hi,

on my Galxy S2 ICS 4.0.3 it's no working,
there is no effect when I click the buttons (bw, zoom, bright, vintage look).

Do you have you any idea?
Thanks. Walter
 

Swissmade

Well-Known Member
Licensed User
Longtime User
Nice Library,

What I mis :signOops:is the Flaslight on off or Auto.

Can this be done??

Thanks for help.
 

Swissmade

Well-Known Member
Licensed User
Longtime User
Do you want the FlashLight on for the Front Camera?

Only Front Camera has Flashlight I think.
Yes I like this on and off also Auto.
Mis this in this library.
The Advance Camera library can do this. But there I have no zoom working.

Many thanks for help.
 

peacemaker

Expert
Licensed User
Longtime User
For ref., sample project of the vbFrontCam 2.0 lib test in B4A v.2.26 BETA:

1) MTK6575 chipset china-phone with back and face cameras under ICS: Ready.Success = False :-(
2) A10 chipset 7'' tablet with only face camera under ICS: Ready.Success =True, but StartPreview without "Try" gives error:

B4X:
** Activity (main) Create, isFirst = true **
There is 1 cameras attached to this device
CAMERA_FACING_FRONT is # 1
Opening Camer # 1
Front Camera failed to open: Fail to connect to camera service
** Activity (main) Resume **
main_fc_ready (B4A line: 94)


FC.StartPreview
java.lang.NullPointerException


   at vb.front.cam.fronty.StartPreview(fronty.java:184)
   at vb.front.camera.main._fc_ready(main.java:516)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:153)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:149)
   at vb.front.cam.fronty$1.surfaceCreated(fronty.java:105)
   at android.view.SurfaceView.updateWindow(SurfaceView.java:1108)
   at android.view.SurfaceView.access$000(SurfaceView.java:87)
   at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:183)
   at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:590)
   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1621)
   at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2446)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:4424)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
   at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException

ACL 4.60 library's StartPreview (of MTK6575 chipset china-phone) for the back camera here gives:

B4X:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main_camera1_ready (B4A line: 62)


camera1.StartPreview
java.lang.NullPointerException


   at xvs.ACL.ACL.StartPreview(ACL.java:196)
   at peacemaker.photoemaillogger.main._camera1_ready(main.java:342)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:153)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:149)
   at xvs.ACL.ACL$2.surfaceCreated(ACL.java:157)
   at android.view.SurfaceView.updateWindow(SurfaceView.java:1108)
   at android.view.SurfaceView.access$000(SurfaceView.java:87)
   at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:183)
   at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:590)
   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1621)
   at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2446)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:4424)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
   at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException

But vbFrontCam 2 lib sample and ACL 4.60 lib sample both work great under Android 2.3 of LG P500 back camera !!!

Any suggestions, help ?


UPDATE: after rebooting MTK6575 chipset china-phone - the face camera is OK with vbFrontCam ! But A10 tablet is still cannot init the face cam
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
B4X:
Sub FC_Ready (Success As Boolean)
    If Success Then
      Try
         If GetOrientation = 1 Then
            FC.Rotate270
         Else If GetOrientation = 3 Then
            FC.Rotate90
         End If
           FC.StartPreview
....

'0 = poitrait, 1 = land-right, 3 = land-left
Sub GetOrientation As Int
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")
Return rotation
End Sub

RotationXXX is OK for using with StartPreview, but, seems, for TakePicture it is working only in the portrait mode: if any of two landscape modes - taking picture is made without Rotation set.
 

ivanomonti

Expert
Licensed User
Longtime User
Problem rotate camera
samsung Galaxy Ace s5830

code

B4X:
#Region - Camera panel {0}

Sub loadCamera
   camera.Initialize(panelscreen,"Camera")
   Dim imview As ImageView
   imview.Initialize("imview")
   imview.Bitmap = LoadBitmap(File.DirAssets,"rotate_64.png")
   panelscreen.AddView(imview,10,10,64,64)
End Sub

Sub imview_Click
   camera.StopPreview
   Try
      Select Case camerarotate
      Case 0
         camera.Rotate90()
         camerarotate = 90
      Case 90
         camera.Rotate180()
         camerarotate = 180
      Case 180
         camera.Rotate270()
         camerarotate = 0
      End Select
   Catch
   End Try
   camera.StartPreview
End Sub

Sub GetOrientation As Int
   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")
   Return rotation
End Sub

Sub Camera_Ready (Success As Boolean)
   Try
      If GetOrientation = 1 Then
         camera.Rotate270
      Else If GetOrientation = 3 Then
         camera.Rotate90
      End If
   Catch
   
   End Try
   Try
      camera.StartPreview
      cameraOn = True
   Catch
      Msgbox("FRONT Camera not working?","Alert")
      cameraOn = False
   End Try
End Sub

Sub Camera_PictureTaken(Data() As Byte)

   Try
      If File.Exists(pathApp, pathPhoto) = False Then
         generatePath
      End If
   Catch 
   
   End Try
      
   Dim out As OutputStream
   
   Dim dt As String
    DateTime.DateFormat = "yyMMddHHmmss"
   Dim now As Long
   now = DateTime.now
    dt = DateTime.Date(now)
   
    out = File.OpenOutput(pathApp, pathPhoto & dt & ".jpg", False)
    out.WriteBytes(Data, 0, Data.Length)
    out.Close
   
    ToastMessageShow("Image saved: " & File.Combine(pathApp, pathPhoto & dt & ".jpg"), True)   
   
   camera.StartPreview
   
   'send the intent that asks the media scanner to scan the file
   
    Dim I As Intent
    I.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", _
        "file://" & File.Combine(pathApp, pathPhoto & dt & ".jpg"))
    Dim p As Phone
    p.SendBroadcastIntent(I)
   
End Sub

#End Region

how can I solve the problem, the room remains in status 1 {GetOrientation = 1 } :sign0085:
 

francoisg

Active Member
Licensed User
Longtime User
I have a question on Android 4.3 and above.
If you take the first photo everything is good ad well.
Afterwards if you start the camera back up again after the first photo that you have taken. the camera never fires the CameraFront_Ready state

Please can you advise
 
Top