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: 2,047
  • ACL4.5.zip
    33.5 KB · Views: 1,468
  • ACL4.6.zip
    359.4 KB · Views: 4,981
Last edited:

ljcomp

Member
Licensed User
Longtime User
Love the Lib, but i have a problem after taking a photo when I load it into an imageview it's rotated 90. Have changed orilandscape/oriportrait which does set the camera preview correctly.
Any ideas where I might be going wrong.
B4X:
Sub Camera1_PictureTaken (Data() As Byte)


    camera1.StartPreview
    Dim out As OutputStream
    out = File.OpenOutput(File.DirRootExternal & "/treescape/images/","Image.jpg", False)
    out.WriteBytes(Data, 0, Data.Length)
    out.Close
   imageview1.Visible = True
   imageview1.Bitmap = LoadBitmap(File.DirRootExternal & "/treescape/images/","Image.jpg")
    'ToastMessageShow("Image saved: " & File.Combine(File.DirRootExternal, "Image.jpg"), True)
   End Sub
Is my picturetaken sub

LJ
 

hdtvirl

Active Member
Licensed User
Longtime User
Hi All, this is a great Library and thank you for putting it together, Iam using the library in an Proof Of Concept I am writting.

I have a problem in that when the Tablet powers down and then is switched back on again the camera object appears to have been disposed of and I get and error objCamera.startpreview.

If anybody else has expereinced this and has a work around/solution I would very much appreciate if you could advise me as to how you did it.

Regadrs

BOB
 

rtesluk

Member
Licensed User
Longtime User
Position Device

Mar 13 2012

I found on my LG phone if I position it horizontal or vertical NOT FLAT, the problem does not happen.

Just a thought.

Regards,

Ray Tesluk
:sign0104:
 

gehrlekrona

Member
Licensed User
Longtime User
Camera shutter sound

Is there a way to turn it off? There is no reason to have a phone make that sound but I can't find anywhere to turn it off.
Anybody who knows how to do it?
 

vb1992

Well-Known Member
Licensed User
Longtime User
Dim p As Phone

p.VOLUME_VOICE_CALL()
p.VOLUME_ALARM()
p.VOLUME_MUSIC()
p.VOLUME_NOTIFICATION()
p.VOLUME_RING()
p.VOLUME_SYSTEM()

p.setmute...............
 

boten

Active Member
Licensed User
Longtime User
Is there a way to get the current zoom setting? If not, can it be added (e.g. Camera.getCurrentZoom) ?
 

boten

Active Member
Licensed User
Longtime User
How can I get the current settings of the camera's resolution?

No Matter what I change the resolution to (in the Camera application) i always get the first available resolution when using
B4X:
Cam.CurrentPictureSizeWidth
Cam.CurrentPictureSizeHeight
In my sgs the "first" available resolution in Camera is 2560x1920, and even if I change the camera's resolution to 640x480 I always get 2560 for CurrentPictureSizeWidth and 1920 for CurrentPictureSizeHeight
 

Nator

Member
Licensed User
Longtime User
Is there a way to save the raw data? I thing i can save the bytes array.. or not?

if you want to save it to a file, I use this, and work

B4X:
Sub Camera1_PictureTaken (Data() As Byte)        
        Dim out As OutputStream
   out = File.OpenOutput(File.DirRootExternal, "1.jpg", False)
   out.WriteBytes(Data, 0, Data.Length)
   out.Close
End Sub
 

Nator

Member
Licensed User
Longtime User
Hi, First of all, great Post, lot of info.

I have a question, I want to send an image (in byte array) with json, y have the image phisical, and in memory, but i don't know how to send it, any Idea?

I use
B4X:
bmpImage.Initialize(File.DirRootExternal,"1.jpg") and try to send 
query="<IMG>"& bmpImage &"</IMG>"
req.InitializePost2("http://190.1.1.0/recive_respuesta3_json.php", query.GetBytes("UTF8"))
But don't work it send some propertys of de images.


PD: sorry for my english is no very good
 
Last edited:

rubino25

Member
Licensed User
Longtime User
if you want to save it to a file, I use this, and work

B4X:
Sub Camera1_PictureTaken (Data() As Byte)        
        Dim out As OutputStream
   out = File.OpenOutput(File.DirRootExternal, "1.jpg", False)
   out.WriteBytes(Data, 0, Data.Length)
   out.Close
End Sub

Tath's right! But it save the image in the jpg format.. Like the sample in the library! If i use the stock camera app, the images are about 5 Mb! With the sample are max 3! Raw data should be larger, or not?

Sorry for bad english..
 

sterlingy

Active Member
Licensed User
Longtime User
Howdy,

I tried out your library with great hopes, but I can't seem to get things to work. The normal methods from the original library are fine, but when I tried to use OriLandscape, I got a Null pointer error, and I also noticed that SetFocusMode doesn't exist. It seems to be FocusMode, but I get the same Null Pointer Error with this, as well.

-Sterling
 

sterlingy

Active Member
Licensed User
Longtime User
I love this library, but several of the ColorEffect modes don't work on my Droid 2. Is there a way to determine which modes don't work, so that my App doesn't display them as a selection?

Cheers,

Sterling
 

Gsquared

Member
Licensed User
Longtime User
Hi XverhelstX,

I didn't notice that the "Optimal Focus Distance" is part of your library. Is that a feature you can add?

Thanks,

G^2
 

Mickster

Active Member
Licensed User
Longtime User
Hey guys,

I'm using this library to change the resolution of images I'm taking on a Toshiba Thrive device, which is working perfectly fine. We are also running the same code on a Motorola Xoom tablet (very similar in specs to the thrive) and the line that modifies the resolution is causing a runtimeexception.

Has anyone seen this before?

Here is the routine causing the crash:

B4X:
Sub Camera1_Ready (Success As Boolean)

   If Success Then
'      Camera1.PictureSize(pnlCamera.Width, pnlCamera.Height)
      Camera1.StartPreview
      btnTakePicture.Enabled = True
   Else
      ToastMessageShow("Cannot open camera.", True)
   End If
   
End Sub

I commented out the line that is causing the issue for clarity.

Thanks :sign0085:
 

nad

Active Member
Licensed User
Longtime User
Testing on 4.6 ZoomIn, ZoomOut, SetZoom and MaxZoom

HTC Desire

OK,OK, No, OK

HTC Desire HD

OK,OK, No, OK

Samsung Galaxy SII

OK,OK, No, OK

Samsung Galaxy SIII

OK,OK, No, OK

So everything seems to work fine but the setzoom. It might be that I don't understand very well what do i need to pass as parameter (value as int, zoom as string, zoom2 as string) What do those zoom string values do?

Also although for all the mobiles the MaxZoom is giving back 30 when I try a ZoomIn in the HTCs the zoom is much higher than in the galaxies.

Thanks for this wonderful library.
 

nad

Active Member
Licensed User
Longtime User
Anyone managed to use the front camara?

I have tried several ways but no luck. Any ideas?

Thanks
 

sioconcept

Active Member
Licensed User
Longtime User
when i try

AdvancedCamera.FlashTorch()
ABZxing.ABGetBarcode("Barcode", "")

the abzing say that it a problem. Maybe because they use the same camera event ?
have you an idea ?
 
Top