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

hackhack

Active Member
Licensed User
Longtime User
Why does it require internet access?

Also,

Could you explain this

toggleFlashLight
Attempts to set camera flash torch/flashlight mode on/off
HACK around
isOn: true = on, false = off
Return type: @return:boolean whether or not we were able to set it

What does hack around mean, how do you specify on/ off. it doesn't seem to return a value.
 
Last edited:

salmander

Active Member
Licensed User
Longtime User
Hi mate, One issue that I am experiencing is that the image when saved is always in a different orientation. Is this issue has been resolved yet?

Thanks
 

danoptic

Member
Licensed User
Longtime User
Get Errors with the colour effects

I get errors when calling
camera1.ColourEffect = "BLACKBOARD"camera1.ColourEffect = "POSTERIZE"camera1.ColourEffect = "SOLARIZE"camera1.ColourEffect = "WHITEBOARD"

Why does it hapen
The other colour efects work fine.

code

Sub mnuSetEffectAqua_Click
camera1.ColourEffect = "AQUA"
End Sub
Sub
mnuSetEffectBlackboard_Click
camera1.ColourEffect = "BLACKBOARD"
End Sub
Sub
mnuSetEffectMono_Click
camera1.ColourEffect = "MONO"
End Sub
Sub
mnuSetEffectNegative_Click
camera1.ColourEffect = "NEGATIVE"
End Sub
Sub
mnuSetEffectNone_Click
camera1.ColourEffect = "NONE"
End Sub
Sub
mnuSetEffectPosterize_Click
camera1.ColourEffect = "POSTERIZE"
End Sub
Sub
mnuSetEffectSolarize_Click
camera1.ColourEffect = "SOLARIZE"
End Sub
Sub
mnuSetEffectWhiteboard_Click
camera1.ColourEffect = "WHITEBOARD"
End Sub
 

salmander

Active Member
Licensed User
Longtime User
Hello,

When I take a picture once, it works fine, but when I again take a picture, I get the following error
B4X:
camera is ready
PictureTaken
imageName: 1.jpg
PictureTaken
imageName: 1.jpg

takeimage_camera1_picturetaken (java line: 309)

java.lang.OutOfMemoryError: (Heap Size=62435KB, Allocated=54903KB)

   at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
   at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:719)
   at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:791)
   at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize2(CanvasWrapper.java:498)
   at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize(CanvasWrapper.java:491)
   at anywheresoftware.b4a.keywords.Common.LoadBitmap(Common.java:1024)
   at com.home.cafiq.test.takeimage._camera1_picturetaken(takeimage.java:309)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:158)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:154)
   at xvs.ACL.ACL$4.onPictureTaken(ACL.java:239)
   at android.hardware.Camera$EventHandler.handleMessage(Camera.java:712)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:156)
   at android.app.ActivityThread.main(ActivityThread.java:5005)
   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)
I am using BitmapExtended library to rotate the picture taken, as in portrait mode, the picture that gets taken is still landscaped.
Here is my code
B4X:
Sub Globals
   Dim out1, out2 As OutputStream
   Dim bmp1, bmp2 As Bitmap
   Dim bmExt As BitmapExtended

        ' more objects/varaibles removed for this post
End Sub
Sub camera1_PictureTaken (Data() As Byte)
   Log("PictureTaken")
   camera1.StartPreview
   imageName = "1"
   imageName = imageName & ".jpg"
   Log("imageName: " & imageName)
   out1 = File.OpenOutput(File.DirDefaultExternal, imageName, False)
   out1.WriteBytes(Data, 0, Data.Length)
   out1.Close
   'out1.Flush
   bmp1 = LoadBitmap(File.DirDefaultExternal, imageName)
   bmp2 = bmExt.rotateBitmap(bmp1, 90)
   out2 = File.OpenOutput(File.DirDefaultExternal, imageName, False)
   bmp2.WriteToStream(out2, 80, "JPEG")
   out2.Close
   'out2.Flush
   ToastMessageShow("Picture taken...", False)
   'displaying the preview
   ImageViewImageTaken.Bitmap = bmp2
   ImageViewImageTaken.Visible = True
   lblImageTaken.Visible = True
   btnCapture.Enabled = True
   btnSend.Visible = True
End Sub

What am I doing wrong?

Please Help?
 

thedesolatesoul

Expert
Licensed User
Longtime User
before the image gets rotated;
h:1840
w:3264
Size in Memory = 3264x1840x4=24023040bytes=22.9MB

When you rotate it you have two bitmaps in memory so: 2x22.9=45.8MB

Also I doubt Data() is GC'd yet so you have 3x22.9=68.73MB in memory

I forget whether the bitmap is stored in Process memory, and I do not know what the default process memory for your device is, but this definitely exceeds any limits.

you will have to decrease the resolution or forgo rotation i think.
 

salmander

Active Member
Licensed User
Longtime User
How can I remove the first two from the memory, after they have been used? So that at one time, there is only one bitmap in the memory?
 

Ennesima77

Member
Licensed User
Longtime User
Hi everyone,
I'm a biginners of B4A programming (and also English), I download and use ACL4.6 in my first application and It works fine.
I have just i little problem: when take first picture and show it in a image view, I can't take any other, and I have to close activity and open it again to take another picture.

I use this code:

First time it work fine, when I try to take a second one (because it's not on focus or not like to the player) preview doesn't start.
What's wrong in my code?

Just another question: As you can see I have had a timer take the file and show it in the preview, if I don't do that the picture doesn't be saved in the file and give me an error, some suggestion about that?
 

mitsusdev

Member
Licensed User
Longtime User
onPreviewFrame use Explanation

Dear XverhelstX,
firstly compliments for your great library!!

So, about my question .....i'm try to use onPreviewFrame for my project....but i don't know about passed params type (Es. Camera As android.hardware.Camera).

Please can you post a small example how use this method?

Into my project i want to be able to detect (during camera preview) automatically changes in brightness.

Thanks a lot.
 
Last edited:

awama

Active Member
Licensed User
Longtime User
.frontCamera gives error message

Hi,

I tried to adjust the front camera, but get an error. What am I doing wrong?

Sub Activity_Resume

camera1.Initialize(Panel1, "Camera1")
camera1.CameraFront2() '.CameraFront
End Sub

Error: java.lang.NullPointerException

I have the Galaxy S2 ICS 4.0.3
 

Silverhawks

Member
Licensed User
Longtime User
Hello first of all congratulations and thanks for the excellent library.:sign0098:
I have the following problem when I acquire the photo is not always the focus. How do I after I did the preview to force the focus before you save the photo?
I try to change focusmode before startpreview but don't work..:sign0085:

I try with Samsung Galaxy S2 and Galaxy S

Sorry for my english...

This is my code
 

danoptic

Member
Licensed User
Longtime User
Zoom example

I m trying to use the zooms function on my galaxy S but i dont succeed!!

Is there any working example of the zoom function working?
I really need that for my app

Thanks
 

mkvidyashankar

Active Member
Licensed User
Longtime User
Try this


B4X:
Camera1.TakePicture
Dim Count As Int 
ToastMessageShow("Attendere.....",True)
TimerVerifica.Initialize("Timer1", 3000)
TimerVerifica.Enabled=True
Preview.Visible=False
bttTakePicture.Enabled=False
camera1.startpreview

End Sub

Sub Timer1_Tick
If File.Exists (File.DirDefaultExternal ,"temp.jpg") Then
ivPicture.Bitmap=LoadBitmapSample(File.DirDefaultE xternal ,"temp.jpg",Preview.Width, Preview.Height )
TimerVerifica.Enabled=False

End If
End Sub
 

Swissmade

Well-Known Member
Licensed User
Longtime User
Very Nice Library but Zoom is not working.:BangHead:

Can anybody help??

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