B4A Library EZcamera

Usage:

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.
End Sub

Sub Activity_Create(FirstTime As Boolean)
Dim cam As EZcamera

cam.Initialize("Cam")
cam.TakePicture(File.DirRootExternal, "TestPic.jpg")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Cam_PictureTaken (FileSaved As Boolean)
   If FileSaved = True Then ToastMessageShow("Picture Saved", True)
End Sub
 

Attachments

  • EZcamera.zip
    3.3 KB · Views: 1,492

pawelmic

Member
Licensed User
Longtime User
Perfect!

Yes, this worked great...thank you :) :sign0188:

I think the original problem I had with NJDUDE's code was that it was interrupted by another event, and like you said sometimes it worked sometimes it didn't, but when you test for null result then you're more likely to succeed.

Thanks everyone for quick turnaround on this, for your thoughts and ideas.

I finally got this to work and it does what I wanted with few lines of code! :)

Of course if this was somehow built into ACL lib that be sweet!
 

djpero

Member
Licensed User
Longtime User
I have some problems using library:
B4X:
src\com\djpero\smsservice\main.java:510: package net.garstangs.ezcamera does not exist
net.garstangs.ezcamera.EZcamera _cam = null;
                      ^
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
I have some problems using library:
B4X:
src\com\djpero\smsservice\main.java:510: package net.garstangs.ezcamera does not exist
net.garstangs.ezcamera.EZcamera _cam = null;
                      ^

Do you have both the xml and the jar file in the library folder? That error seems to indicate it cant find the class, but since it knows of the class it is likely you have the xml but not the jar file.
 

Mahares

Expert
Licensed User
Longtime User
@Roger: This is a very nice little library. Is there a way to programmatically set the picture resolution and quality so its size is a few KBs instead of MBs.
Thank you
 

djpero

Member
Licensed User
Longtime User
Do you have both the xml and the jar file in the library folder? That error seems to indicate it cant find the class, but since it knows of the class it is likely you have the xml but not the jar file.

;) Beginners error. Thnx
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
@Roger: This is a very nice little library. Is there a way to programmatically set the picture resolution and quality so its size is a few KBs instead of MBs.
Thank you

All this does is call on the built-in camera app's image capture intent to take the picture. It passes a file name and directory to store it then gets Success/Fail. The interface on my test device has options for effects and such just like the default app, but I didnt play with it enough yet to see if it gives resolution options. I'll add whatever options the intent call supports...I was just glad to finally get it working. If I can figure out the issue with getting the smaller thumbnail image data in the returned intent I will add it, but my test device here always returned a null intent and only gave the intent success result.
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Played with my Library a little in my application today and am pretty pleased with the results. It appears to detect rotation fine and save pictures well for what I need. I did have one thing that was missing from this and B4A that I added- The ability to get an image file's dimensions without loading the image. This should allow for better calculations to use with the existing LoadBitmapSample function in B4A. I just tossed the function in and didn't change the version number for those interested.
 

Attachments

  • EZcameraDimensions.zip
    3.7 KB · Views: 769

Eduard

Active Member
Licensed User
Longtime User
Played with my Library a little in my application today and am pretty pleased with the results. It appears to detect rotation fine and save pictures well for what I need. I did have one thing that was missing from this and B4A that I added- The ability to get an image file's dimensions without loading the image. This should allow for better calculations to use with the existing LoadBitmapSample function in B4A. I just tossed the function in and didn't change the version number for those interested.

Thanks! I really like this library. Small, simple, good! :sign0098:
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Glad you like it. I developed it while waiting on a better camera library (Latest B4A library is looking good, but still missing some things I'd like to see). On the device I'm using now it gives me all the advanced features I need including storing EXIF GPS which is nice. Even iPhones give me issues with that. If I access my web interface on them and upload pictures it strips them out for "Privacy Reasons". When you share pictures on it by message/email you have to copy it instead of hitting the share button otherwise it strips it and recompresses it too...so glad Android doesn't have issues with that. EXIF GPS is very important in my main app for tracking Evidence.
 

Eduard

Active Member
Licensed User
Longtime User
Library doesn't seem to work all the time.

It seems that sometimes the sub Cam_PictureTaken is never called, sometimes the sub is called and FileSaved=true but there is no image.

Orientation does work for a external app I used, but not for the default camera app of Samsung Galaxy SII

:sign0013:

Any ideas to solve this?
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
There will likely be varied results depending on the device. Since it just calls the built-in intent for the camera it is up to the Mfg to determine how to handle it. Some write nice custom interfaces, some use standard Android, and others are just plain bad. I imagine the newer Android versions will handle it better than old. I have a tablet with Android 2.3.4 that does well and a phone with 4.0.x that did well.

There is supposed to be two interfaces for this Intent Call- This one you pass a filename for and another that passes back the image as Intent Data. The Intent Data always had issues and usually was a tiny thumbnail. Some devices support passing a flag that had it return a larger image in the data, but not all allowed it. Now that Erel has the new Camera Library out and even posted JAVA Source it may be the better way to go.
 

Eduard

Active Member
Licensed User
Longtime User
Thanks, I'll go for the Camera lib v2.1 for now.

When I have more time I'll try to do this with intent.
 

yuhong

Member
Licensed User
Longtime User
I use EZcamera in a Service named RunCamService:
B4X:
Sub Service_Create

End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub

Sub Service_Destroy

End Sub

Sub TakePicture
   Dim cam As EZcamera
   cam.Initialize("Cam")
   cam.TakePicture(File.DirRootExternal, "1.jpg")
End Sub

Sub Cam_PictureTaken (FileSaved As Boolean)
    If FileSaved = True Then 
          SavePictrue
    End If
End Sub

In my Activity,I call it:
B4X:
CallSubDelayed(RunCamService,"TakePicture")

but,Camera don't show.

now,I use a activity run Camera, it is OK !
but, this activity is show a blank window before show Camera,it is't good.
 
Last edited:

gadgetmonster

Active Member
Licensed User
Longtime User
For those of you who have tried EZCamera only to find that on occasion it didn't return the image I have a workaround.

I used EZCamera because I wanted to use the on device camera app but experience a problem on some devices (Galaxy S3 for example) where it would allow me to take a picture and it would save the image but (as others have stated) the Picture_Taken event never got called. So here's my work around.

1. Create a global variable named cameraActivated as Boolean
2. Prior to calling cam.TakePicture, set this variable to True
3. Then in Activity_Resume check for cameraActivated = true and look for the photo.

Example:

Code to start EZCamera:
B4X:
Dim cam As EZcamera
      
cameraActivated = True
camFileName =  "test.jpg"
cam.Initialize("Cam")
cam.TakePicture(File.DirRootExternal, camFileName)

This will start the camera and allow you to take a picture. If you accept the picture then it will be saved as Test.jpg. Once the picture is saved you will return to your Activity, so in the Activity_Resume:

B4X:
If cameraActivated Then
   If File.Exists(File.DirRootExternal, camFileName) = True Then
      ' Process Image
   End If
   cameraActivated = False
End If

If the image was discarded then you will still return to Activity_Resume where this code will simply set cameraActivated to false.

Hope this helps someone
 

gadgetmonster

Active Member
Licensed User
Longtime User
Hi Roger, My app uses your excellent camera library but recently I have had three users report a problem.

I have an activity with a take picture button. This calls EZCamera to take the photo. When they click the Save button to keep the photo, the photo is saved correctly to the given location/file. When returning to the calling activity, the activity_create is called which indicates that for some reason the activity had been canceled.

All three users seem to have Galaxy S3's on Verizon. I have tested on a UK Galaxy S3 and my Galaxy note 2 and it works fine here.

Have you seen this before or have any ideas what's going on?
 
Top