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!
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.
b.
5) Antibanding


6) Colour Effects

a.
7) Focus Mode


8) Scene Mode


9) White Balance



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

XverhelstX

Well-Known Member
Licensed User
Longtime User

I don't know why I did this ;p.
The output seems good that people can see whether they are using to get or change the variable.
Personally, I prefer this method because it's easier to see.

But if you guys would like it to change
from setXXX and getXXX to just XXX, tell me.

I will also add the version to the ZIP.

Thx for your feedback Agraham.

Tomas

I will also
 

Ratters

Member
Licensed User
Longtime User
Advancedcamera V2.0 - Fantastic !

Hi XverhelstX,

fantastic news...

I really appreciate your time, I know myself what its like to juggle events around

Excellent library...

If I have any issues, I'll post it back on this thread.

Cheers...

Robbie
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hey Robbie,

Thank you

Although, I have a question on your previous answer. o)

Sorted with the camera1.CameraFront, silly me, on the Galaxy S I used the camera1.CameraBack to use the camera on the same side as the screen, I just thought the screen side was the front of the camera, Doh!

Hope this help others...

Robbie

So here you mean that the camera on your screen side (facing to you) is the back camera?
Then it's a bug in the library and I have to switch it because the front camera is on the screen side.

Tomas
 

Ratters

Member
Licensed User
Longtime User
Hi XverhelstX,

Yep, thats right, I found this by trial and error testing... I've only tried it on a Samsung Galaxy S phone, I have no other to try, sorry.

I haven't tried it yet on the new release... 2 mins

Robbie
 

Ratters

Member
Licensed User
Longtime User
Hi XverhelstX,

camera1.CameraBack uses the camera on the screen side on the Galaxy S.

Hope this helps.

Cheers

Robbie
 

Ratters

Member
Licensed User
Longtime User
And as if by magic....

That's great Tomas, tried and tested... That was quick

camera1.CameraFront is now screen side.

Robbie
 

Ratters

Member
Licensed User
Longtime User
Sorry Tomas,
may have found another bug,

Using;

Dim out As OutputStream
out = File.OpenOutput(File.DirDefaultExternal, "photoMe.jpg", False)
out.WriteBytes(data, 0, data.Length)
out.Close


I am unable to capture the outputstream using the front camera. The screen appears green and the camera sound is heard but that's it - it just displays a constant green screen in the relating panel.
 

Shay

Well-Known Member
Licensed User
Longtime User
Great job, thank you for your effort
:sign0098:
 

NJDude

Expert
Licensed User
Longtime User
Do the "effects" work?, I've tried the sample code and I get an error on SEPIA, no such member.

NOTE: I noticed the posted sample is a little "old" it seems things were changed on version 2, also, there is a typo on the FLASH section, I see that the instruction to turn the flash off is FlashOn instead of FlashOff.
 
Last edited:

XverhelstX

Well-Known Member
Licensed User
Longtime User
U should first check with getSupportedeffect or something.
It returns a list with the supported effects. See page 2 for mor information on this topic.

XverhelstX

Sent from my SE Xperia Play using Tapatalk.

Edit: yeah, i will edit the topic later. First take some sleep.
 
Last edited:

Omar

Member
Licensed User
Longtime User
Dear XverhelstX

Thank you very much for this excellent library, I am encountering an error with the basic command:

Camera1.FlashOn()

Camera1 has been dim'd as an AdvancedCamera and the library is loaded but I keep getting the java.lang.NullPointerException error when compiling on the above code.

Could you please advise what am I doing wrong?
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
On what android version are u testing it on?
and what android smartphone u test it on?
The flashlight is supported since: API Level 5; Android 2.0).

Did you also do:
B4X:
dim Camera1 as AdvancedCamera
Camera1.FlashOn()

XverhelstX
 

Omar

Member
Licensed User
Longtime User
Hi XverhelstX,

I am using the HTC Desire HD. For some reason it keeps crashing on:

Camera1.FlashOn()


I am using Android 2.2.1

Also I tried only using:

dim Camera1 as AdvancedCamera
Camera1.FlashOn()

I received the same error message: java.lang.NullPointerException

Thanks for your help to look into this.
 
Last edited:

Omar

Member
Licensed User
Longtime User
Thank you for your quick help.

I tried the code:

Msgbox(camera1.getSupportedFlashMode(),"")

But I get the error message: Array Expected.

Not sure what is wrong with this.



 

Omar

Member
Licensed User
Longtime User
Thanks for the clarification. I will try the code shortly and update on what I receive back. I will get back to you after a little while.

Thank you


You have to use:

B4X:
   Msgbox(Camera1.getSupportedFlashMode,"")

this is without the () after getSupportedFlashMode.

XverhelstX
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
ok, the problem will probably be related to the device as some manufacturers have different settings. I have to go now, but I will update the library tomorrow with some more stuff and I think (not sure) I can fix it.

XverhelstX
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…