B4A Library [Class] CameraEx - Extends the camera library functionality

Status
Not open for further replies.
Example based on B4XPages: https://www.b4x.com/android/forum/threads/b4x-b4xpages-barcode-reader.120417/#content

CameraEx class wraps the Camera object and using reflection and other code it extends its functionality.

CameraEx class requires Android 2.3+ and depends on Camera library v2.20+
CameraEx features:
  • Easily open the back or front camera
  • Preview images and saved images orientation will match the device orientation (all orientations are supported)
  • Gives access to Camera.Parameters native class (flashmode, picture size, effects and other settings)
  • Includes methods to convert preview images to JPEG and to save the taken pictures.
  • It should be simple to add more methods to this class

SS-2012-11-28_12.18.31.png


See this page for the constant values and other possible methods:
https://developer.android.com/reference/android/hardware/Camera.Parameters.html

Note that you should call CommitParameters after changing one or more parameters.

CameraExClass module is included in the attached example.

V1.30 is attached - Includes various new methods.

v1.20 - Includes all the various posts in this thread as well as AutoFocusAndTakePicture method which first calls AutoFocus and then takes a picture (if AutoFocus was successful).

Edit (06/2018): A new version was uploaded with targetSdkVersion set to 26.
 

Attachments

  • CameraEx.zip
    13.2 KB · Views: 3,981
Last edited:

padvou

Active Member
Licensed User
Longtime User
Please try to start new threads for new questions. This thread is quite mixed...

@MotoMusher, try to add a short delay in FocusDone event. You can use CallSubDelayed to call TakePicture.

@padvoud why do you need to call CloseNow?

I tried it as a workaround for the app freezing.
If you would please take a look at the log I attached, this is my main issue for resolving.
 

ivanomonti

Expert
Licensed User
Longtime User
How do I add custom filters as well as frames in this class!!

In addition, it is possible to enter GPS data

Thank
 

birnesoft

Active Member
Licensed User
Longtime User
how can I setPreviewSize( width, height) from camera

I've listed the possible sizes with this code

Dim pl As List
r.target = parameters
pl=r.RunMethod("getSupportedPreviewSizes")

For m = 0 To pl.Size-1
r.target = pl.Get(m)
Dim width = r.GetField("width"), height = r.GetField("height") As Int
Log (width&"-"&height)
Next

pl is:

(ArrayList) [android.hardware.Camera$Size@57dac0, android.hardware.Camera$Size@9fbc30, android.hardware.Camera$Size@afb580, android.hardware.Camera$Size@13f7860, android.hardware.Camera$Size@1676730, android.hardware.Camera$Size@1a74bb0, android.hardware.Camera$Size@27eefd0]

that means:

176-144
320-240
352-288
640-480
720-480
848-480
1280-720

and now I want to set the best size

Java: public void setPreviewSize (int width, int height)

setPreviewSize (1280,720 )

How can I do this??:sign0163:

thank Björn
 

birnesoft

Active Member
Licensed User
Longtime User
when I change the previewSize the function PreviewImageToJpeg

don't work anymore (program crash and bad picture) ???


r.target = parameters
r.RunMethod3("setPreviewSize", 1280, "java.lang.int", 720, "java.lang.int")

and

Sub Camera1_Preview (PreviewPic() As Byte)
Dim jpeg() As Byte = PreviewImageToJpeg(PreviewPic, 80)
 

birnesoft

Active Member
Licensed User
Longtime User
adb Logcat program crash after calling PreviewImageToJpeg(PreviewPic, 80)

05-30 22:27:29.475 23878 23878 D skia : onFlyCompress
05-30 22:27:29.538 23878 23884 D dalvikvm: GC_FOR_MALLOC freed 920K, 53% free 31
66K/6663K, external 4559K/5684K, paused 18ms
05-30 22:27:29.897 23915 23915 I DEBUG : *** *** *** *** *** *** *** *** *** *
** *** *** *** *** *** ***
05-30 22:27:29.897 23915 23915 I DEBUG : Build fingerprint: 'motorola/DACH/umt
s_milestone2:2.3.4/MILS2_U6_4.1-22/1317096749:user/release-keys'
05-30 22:27:29.897 23915 23915 I DEBUG : pid: 23878, tid: 23878 >>> br.speedc
am <<<
05-30 22:27:29.897 23915 23915 I DEBUG : signal 11 (SIGSEGV), code 2 (SEGV_ACC
ERR), fault addr 406beb31
05-30 22:27:29.897 23915 23915 I DEBUG : r0 002c83f0 r1 406beb30 r2 002ef19
8 r3 002f05a0
.....

f400f4
05-30 22:27:29.913 23915 23915 I DEBUG : d30 0000000000000000 d31 3ff0000000
000000
05-30 22:27:29.913 23915 23915 I DEBUG : scr 60000012
05-30 22:27:29.913 23915 23915 I DEBUG :
05-30 22:27:29.960 23915 23915 I DEBUG : #00 pc 0005b254 /system/li
b/libandroid_runtime.so
05-30 22:27:29.960 23915 23915 I DEBUG : #01 pc 0005b528 /system/li
b/libandroid_runtime.so
05-30 22:27:29.960 23915 23915 I DEBUG : #02 pc 0005b67a /system/li
b/libandroid_runtime.so
05-30 22:27:29.960 23915 23915 I DEBUG : #03 pc 0005b754 /system/li
b/libandroid_runtime.so
05-30 22:27:29.967 23915 23915 I DEBUG : #04 pc 00011e74 /system/li
b/libdvm.so
05-30 22:27:29.967 23915 23915 I DEBUG :
05-30 22:27:29.967 23915 23915 I DEBUG : code around pc:
05-30 22:27:29.967 23915 23915 I DEBUG : ad35b234 ea4f2400 46260b65 eb066885 e
b02080b
05-30 22:27:29.967 23915 23915 I DEBUG : ad35b244 686f0904 fb072500 eb031708 e
0080804
05-30 22:27:29.967 23915 23915 I DEBUG : ad35b254 ac01f817 a005f809 ac02f817 a
005f808
05-30 22:27:29.967 23915 23915 I DEBUG : ad35b264 37023501 dbf34565 44643601 d
1e32e08
05-30 22:27:29.967 23915 23915 I DEBUG : ad35b274 8ff0e8bd 23026c48 6c4a6083 3
b0160d3
05-30 22:27:29.967 23915 23915 I DEBUG :
05-30 22:27:29.967 23915 23915 I DEBUG : code around lr:
05-30 22:27:29.967 23915 23915 I DEBUG : ad35b50c f7c84628 4605ee22 9003a825 9
300e029
05-30 22:27:29.967 23915 23915 I DEBUG : ad35b51c 46384632 462b4651 9004f8cd f
e7ef7ff
05-30 22:27:29.967 23915 23915 I DEBUG : ad35b52c 68b82200 30e0f8d4 18d36801 f
b019802
05-30 22:27:29.967 23915 23915 I DEBUG : ad35b53c f84b0303 07d33022 1053d40c 0
ea0f10d
05-30 22:27:29.967 23915 23915 I DEBUG : ad35b54c f103fb08 0c83eb0e 18691870 0
c2cf84c
05-30 22:27:29.967 23915 23915 I DEBUG :
05-30 22:27:29.967 23915 23915 I DEBUG : stack:
05-30 22:27:29.967 23915 23915 I DEBUG : bed0e49c 10101010
05-30 22:27:29.967 23915 23915 I DEBUG : bed0e4a0 10101010
0
05-30 22:27:29.967 23915 23915 I DEBUG : bed0e4f8 bed0e514
05-30 22:27:29.967 23915 23915 I DEBUG : bed0e4fc ad35b52d /system/lib/l
ibandroid_runtime.so
05-30 22:27:29.975 23915 23915 I DEBUG : #01 bed0e500 00000000
0
05-30 22:27:29.975 23915 23915 I DEBUG : bed0e51c afd1369d /system/lib/l
ibc.so
05-30 22:27:29.975 23915 23915 I DEBUG : bed0e520 00000064
0
05-30 22:27:29.975 23915 23915 I DEBUG : bed0e530 9d72e900 /system/lib/l
ibjpeg.so
05-30 22:27:29.975 23915 23915 I DEBUG : bed0e534 bed0eb88

05-30 22:27:29.975 23915 23915 I DEBUG : bed0e54c 9d704d84 /system/lib/l
ibjpeg.so
05-30 22:27:29.975 23915 23915 I DEBUG : bed0e550 00000000

05-30 22:27:29.975 23915 23915 I DEBUG : bed0e57c 9d7064c0 /system/lib/l
ibjpeg.so
05-30 22:27:29.975 23915 23915 I DEBUG : bed0e580 00000000

05-30 22:27:29.975 23915 23915 I DEBUG : bed0e5a4 bed0eb88
05-30 22:27:29.975 23915 23915 I DEBUG : bed0e5a8 ad35b4b9 /system/lib/l
ibandroid_runtime.so
05-30 22:27:29.975 23915 23915 I DEBUG : bed0e5ac 405ddb30

05-30 22:27:29.983 23915 23915 I DEBUG : bed0e5c0 404f0ca0
05-30 22:27:29.983 23915 23915 I DEBUG : bed0e5c4 ad35b67d /system/lib/l
ibandroid_runtime.so
05-30 22:27:30.303 6305 6325 I BootReceiver: Copying /data/tombstones/tombston
e_04 to DropBox (SYSTEM_TOMBSTONE)
05-30 22:27:30.335 6294 6294 D CameraHal: stopPreview
05-30 22:27:30.335 6294 6294 I HPAndroidHAL: APILOG: S1Up
05-30 22:27:30.335 6294 6294 D CameraHal: stop preview thread
05-30 22:27:30.335 6305 6337 E InputDispatcher: channel '40b1b810 br.speedcam/
br.speedcam.main (server)' ~ Consumer closed input channel or an error occurred.
events=0x8
05-30 22:27:30.335 6305 6337 E InputDispatcher: channel '40b1b810 br.speedcam/
br.speedcam.main (server)' ~ Channel is unrecoverably broken and will be dispose
d!
05-30 22:27:30.335 6296 6296 D Zygote : Process 23878 terminated by signal (1
1)
05-30 22:27:30.350 6294 6294 I HPAndroidHAL: APILOG: Disable Preview
05-30 22:27:30.350 6294 6294 D CameraHal: CameraHal release
05-30 22:27:30.358 6294 6294 D CameraHal: deinitPvOverlay()
05-30 22:27:30.358 6294 6294 I HPAndroidHAL: APILOG: DeinitializePreviewMemory

05-30 22:27:30.436 6305 6325 D dalvikvm: GC_FOR_MALLOC freed 170K, 31% free 98
66K/14279K, external 3998K/5599K, paused 130ms
05-30 22:27:30.436 6305 6325 I dalvikvm-heap: Grow heap (frag case) to 15.849M
B for 65056-byte allocation
05-30 22:27:30.491 6294 23911 I HPAndroidHAL: Exiting thread OMAPHAL_Thread (ID
: 0x5aaa8)
05-30 22:27:30.491 6294 6294 I HPAndroidHAL: APILOG: ExitHPLibraries
05-30 22:27:30.491 6305 6458 D TIOverlay: overlay_destroyOverlay:IN dev (0x29d
af0) and overlay (0x3b8d00)
05-30 22:27:30.491 6305 6458 I TIOverlay: Destroying overlay/fd=211/obj=003b8d
00
05-30 22:27:30.491 6305 6458 D TIOverlay: overlay_destroyOverlay:OUT
05-30 22:27:30.491 6294 23898 I HPAndroidHAL: Exiting thread CaptureDirectorThr
ead (ID: 0x1750b0)
05-30 22:27:30.491 6294 6294 I HPAndroidHAL: APILOG: state machine shutting do
wn...
05-30 22:27:30.491 6294 23887 I HPAndroidHAL: Exiting thread HALThread (ID: 0xb
8c20)
05-30 22:27:30.491 6294 23888 I HPAndroidHAL: Exiting thread AutoExposureThread
(ID: 0xb6f88)
05-30 22:27:30.491 6294 23889 I HPAndroidHAL: Exiting thread RenderingAnalysisM
odule (ID: 0x158f28)
05-30 22:27:30.491 6294 23890 I HPAndroidHAL: Exiting thread BoxcarThread (ID:
0x158f68)
05-30 22:27:30.491 6294 23891 I HPAndroidHAL: Exiting thread S2ProcessingThread
(ID: 0x137cc8)
05-30 22:27:30.499 6294 23892 I HPAndroidHAL: Exiting thread LensThread (ID: 0x
137d08)
05-30 22:27:30.499 6294 23893 I HPAndroidHAL: Exiting thread FocusThread (ID: 0
xcbb90)
05-30 22:27:30.499 6294 23894 I HPAndroidHAL: Exiting thread paxelMotionThread
(ID: 0xcbbe8)
05-30 22:27:30.499 6294 23895 I HPAndroidHAL: Exiting thread CallbackThread (ID
: 0xcf650)
05-30 22:27:30.499 6294 23896 I HPAndroidHAL: Exiting thread FlickerThread (ID:
0xcf690)
05-30 22:27:30.499 6294 23897 I HPAndroidHAL: Exiting thread FaceDetectThread (
ID: 0x14c9b8)
05-30 22:27:30.499 6294 23899 I HPAndroidHAL: Exiting thread S2PostProcessingTh
read (ID: 0x1750f0)
05-30 22:27:30.499 6294 6294 I HPAndroidHAL: APILOG: components shutting down.
..
05-30 22:27:30.499 6294 6294 I HPAndroidHAL: APILOG: all components uninitiali
zed.

05-30 22:27:30.499 6294 6294 I HPAndroidHAL: APILOG: Destroying Component 0.
05-30 22:27:30.538 6294 6294 I HPAndroidHAL: APILOG: all components destroyed.

05-30 22:27:30.538 6294 6294 I HPAndroidHAL: APILOG: library shutdown complete
.
05-30 22:27:30.569 6305 7189 D dalvikvm: GC_FOR_MALLOC freed <1K, 31% free 992
9K/14343K, external 3998K/5599K, paused 121ms
05-30 22:27:30.569 6305 6471 I WindowManager: WIN DEATH: Window{40b1b810 br.sp
eedcam/br.speedcam.main paused=false}
05-30 22:27:30.624 6294 6294 D CameraHal: CameraHal destructor
05-30 22:27:30.624 6294 6294 D CameraHal: CameraHal release
05-30 22:27:30.624 6294 6294 D CameraSettings: CameraSettings destructor
05-30 22:27:30.686 6305 6325 D dalvikvm: GC_FOR_MALLOC freed 178K, 33% free 97
51K/14343K, external 3998K/5599K, paused 94ms
05-30 22:27:30.686 6305 7189 I ActivityManager: Process br.speedcam (pid 23878
) has died.
05-30 22:27:30.686 6305 6468 I WindowManager: WIN DEATH: Window{40bfa7a8 Surfa
ceView paused=false}
05-30 22:27:30.694 6305 6461 I WindowManager: Setting rotation to 0, animFlags
=1
05-30 22:27:30.741 6305 7189 I ActivityManager: Config changed: { scale=1.0 im
si=262/1 loc=de_DE touch=3 keys=2/1/2 nav=2/1 orien=1 layout=34 uiMode=17 seq=14
6}
05-30 22:27:30.944 6305 6472 W InputManagerService: Got RemoteException sendin
g setActive(false) notification to pid 23878 uid 10143
05-30 22:27:31.233 23822 23822 W WidgetAidService: BroadcastReceiver onReceive c
alled
05-30 22:27:31.241 23822 23822 D WidgetAidService: ACTION_HOME_SCREEN_CHANGED -
2
05-30 22:27:32.257 6387 6387 D RadioSignalLevel: Gsm Radio Signal level: 4
05-30 22:27:32.960 6305 6335 D dalvikvm: GC_EXPLICIT freed 331K, 33% free 9621
K/14343K, external 3998K/5599K, paused 135ms
^C

so much crazy stuff ... I don't understand. :sign0013:

Björn
 

birnesoft

Active Member
Licensed User
Longtime User
find no limits in B4A

Juhu,:sign0060:...Erel you are unbelievable, it works.

I've not make commitParameters

U are the best. Another La Ola wave 4U :wav:

Thanks 1000 times

:) I find no limits in B4A :)
 

yckhor

Member
Licensed User
Longtime User
Hi Erel,
I am attaching 2 screen capture of my app. The camera ex works beautifully but the only issue I am facing is that the captured image seems off proportion in landscape and portrait mode (activity with no title bar & full screen).

I had tested this on the sample camera app provided with this library and produced similar results. This, however, does not happen in the android stock standard camera app.

FYI, I am using a HTC Desire HD rooted and running Android 4.2.2.

Any help would be appreciated. Thanks!
 

Attachments

  • Screenshot_2013-06-25-19-28-14.jpg
    Screenshot_2013-06-25-19-28-14.jpg
    9.4 KB · Views: 217
  • Screenshot_2013-06-25-19-27-53.jpg
    Screenshot_2013-06-25-19-27-53.jpg
    8.2 KB · Views: 215
Last edited:

yckhor

Member
Licensed User
Longtime User
Hi Erel,
The picture size is not an issue, yes, I tried. I had attached the 2 pictures took in landscape & portrait orientation and both looks proportionally correct (notice the little girl figure with a hula loop). It is the preview in panel before a photo is being snapped that looks out of proportion. If you look at the snapshots in my earlier post, you can see the 2 screen snapshot (with a round shutter button) that did not look right in portrait mode, everything looks longish.. am I missing something? Title bar is hidden and it is in Full Screen.:sign0085:

EDIT: Now I realize why you asked me to check SetPictureSize. It's my mistake not illustrating clearly. It's the preview image that's out of proportion not the captured image.
 

Attachments

  • 1.jpg
    1.jpg
    14.5 KB · Views: 219
  • 2.jpg
    2.jpg
    15.6 KB · Views: 209
Status
Not open for further replies.
Top