B4A Library CameraView - Take Pictures, record Video with the Camera

Discussion in 'Additional libraries, classes and official updates' started by DonManfred, Aug 26, 2017.

  1. DonManfred

    DonManfred Expert Licensed User

    this is a quick (and incomplete) hack for this github project.

    CameraView
    Version:
    1
    • CameraView
      Events:
      • onCameraClosed ( As )
      • onCameraOpened (options As Object)
      • onExposureCorrectionChanged (newValue As Float, bounds() As Float, fingers() As Object)
      • onFocusEnd (success As Boolean, x As Int, y As Int)
      • onFocusStart (x As Int, y As Int)
      • onOrientationChanged (orientation As Int)
      • onPictureTaken (jpeg() As Byte)
      • onVideoTaken (path As String, filename As String)
      • onZoomChanged (newValue As Float, bounds() As Float, fingers() As Object)
      Fields:
      • ba As BA
      Methods:
      • BringToFront
      • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
      • Initialize (EventName As String)
      • Invalidate
      • Invalidate2 (arg0 As Rect)
      • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
      • IsInitialized As Boolean
      • RemoveView
      • RequestFocus As Boolean
      • SendToBack
      • SetBackgroundImageNew (arg0 As Bitmap) As BitmapDrawable
      • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
      • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
      • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
      • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
      • capturePicture
        Asks the camera to capture an image of the current scene.
        This will trigger {@link CameraListener#onPictureTaken(byte[])} if a listener
        was registered.

        Note that if sessionType is {@link SessionType#VIDEO}, this
        might fall back to {@link #captureSnapshot()} (that is, we might capture a preview frame).
      • captureSnapshot
        Asks the camera to capture a snapshot of the current preview.
        This eventually triggers {@link CameraListener#onPictureTaken(byte[])} if a listener
        was registered.

        The difference with {@link #capturePicture()} is that this capture is faster, so it might be
        better on slower cameras, though the result can be generally blurry or low quality.
      • clearCameraListeners
        Clears the list of {@link CameraListener} that are registered
        to camera events.
      • destroy
      • pause
        Stops the current preview, if any was started.
        This should be called onPause().
      • setLocation (latitude As Double, longitude As Double)
        Set location coordinates to be found later in the jpeg EXIF header
        latitude: current latitude
        longitude: current longitude
      • setSessionPicture
      • setSessionVideo
      • start
        Starts the camera preview, if not started already.
        This should be called onResume(), or when you are ready with permissions.
      • startAutoFocus (x As Float, y As Float)
        Starts an autofocus process at the given coordinates, with respect
        to the view width and height.
        x: should be between 0 and getWidth()
        y: should be between 0 and getHeight()
      • startCapturingVideo (path As String, filename As String)
        Starts recording a video with selected options. Video will be written to the given file,
        so callers should ensure they have appropriate permissions to write to the file.
        file: a file where the video will be saved
      • stop
        Stops the current preview, if any was started.
        This should be called onPause().
      • stopCapturingVideo
        Stops capturing video, if there was a video record going on.
        This will fire {@link CameraListener#onVideoTaken(File)}.
      • toggleFacing As Facing
        Toggles the facing value between {@link Facing#BACK}
        and {@link Facing#FRONT}.
        Return type: @return:the new facing value
      • toggleFlash As Flash
        Toggles the flash mode between {@link Flash#OFF},
        {@link Flash#ON} and {@link Flash#AUTO}, in this order.
        Return type: @return:the new flash value
      Properties:
      • Background As Drawable
      • CameraOptions As CameraOptions [read only]
        Returns a {@link CameraOptions} instance holding supported options for this camera
        session. This might change over time. It's better to hold a reference from
        {@link CameraListener#onCameraOpened(CameraOptions)}.
      • CaptureSize As Size [read only]
        Returns the size used for the capture,
        or null if it hasn't been computed yet (for example if the surface is not ready).
      • Color As Int [write only]
      • CropOutput As Boolean [write only]
        Whether we should crop the picture output to match CameraView aspect ratio.
        This is only relevant if CameraView dimensions were somehow constrained
        (e.g. by fixed value or MATCH_PARENT) and do not match internal aspect ratio.

        Please note that this requires additional computations after the picture is taken.
      • Enabled As Boolean
      • ExposureCorrection As Float
        Returns the current exposure correction value, typically 0
        at start-up.
      • ExtraProperties As ExtraProperties [read only]
        If present, returns a collection of extra properties from the current camera
        session.
      • Facing As Facing
        Gets the facing camera currently being used.
      • Flash As Flash
        Gets the current flash mode.
      • Grid As Grid
        Gets the current grid mode.
      • Height As Int
      • JpegQuality As Int [write only]
        Sets the JPEG compression quality for image outputs.
      • Left As Int
      • Padding()() As Int
      • Parent As Object [read only]
      • PreviewSize As Size [read only]
        Returns the size used for the preview,
        or null if it hasn't been computed (for example if the surface is not ready).
      • SessionType As SessionType
        Gets the current session type.
      • SnapshotSize As Size [read only]
        Returns the size used for capturing snapshots.
        This is equal to {@link #getPreviewSize()}.
      • Started As Boolean [read only]
        Returns whether the camera has started showing its preview.
      • Tag As Object
      • Top As Int
      • VideoQuality As String
        Gets the current video quality.
      • Visible As Boolean
      • WhiteBalance As WhiteBalance
        Returns the current white balance behavior.
      • Width As Int
      • Zoom As Float
        Returns the current zoom value, something between 0 and 1.
     

    Attached Files:

    Last edited: Aug 26, 2017
  2. Johan Schoeman

    Johan Schoeman Expert Licensed User

    I was busy with it....lol
     
  3. DonManfred

    DonManfred Expert Licensed User

    I can upload the source and you can complete it if you want...
    There is no support for the CameraOptions as yet
     
  4. Rantor777

    Rantor777 Member Licensed User

    Yes, Upload the Source code, Please

    +100 :)
     
    Rockefeller Goldman likes this.
  5. DonManfred

    DonManfred Expert Licensed User

    Here
     

    Attached Files:

    • src.zip
      File size:
      5.8 KB
      Views:
      133
  6. Rantor777

    Rantor777 Member Licensed User

    Thanks for the Source, I will see it and study it to learn something.

    @DonManfred
     
    Rockefeller Goldman likes this.
  7. Mashiane

    Mashiane Expert Licensed User

    Hi

    Please add, flash toggle event and facing event for one to add code when that happens. Also please activate the event to capture a time based video.

    This is nice and powerful, thanks.
     
    Rockefeller Goldman likes this.
  8. KingEdem

    KingEdem Member Licensed User

    Hi Don,

    I would like to superimpose (transparent 30%) date n time on the recording video and snap picture. Please suggest.
     
  9. DonManfred

    DonManfred Expert Licensed User

    I don´t know if this is possible. Check the Githubprojects Source.
    I can upload the source of this lib so you can extend it if you want to.
     
  10. GDO

    GDO Member Licensed User

    Hello,

    Could you please add an : onPreview(pic() as Bytes) event ?

    Thank you.
     
  11. DonManfred

    DonManfred Expert Licensed User

    The library does not provide this feature. Not possible.
     
    GDO likes this.
  12. GDO

    GDO Member Licensed User

    ok thank you.
     
  13. Ivan Aldaz

    Ivan Aldaz Member Licensed User

    Hi. I've been trying this library and find it very simple and useful, but there are a couple of things I can't handle.

    - The first is video quality. It's set by
    Code:
    cam.VideoQuality = "XXXXXXXX"
    ...and can be seen later with
    Code:
    Log("cam.CaptureSize: " & cam.capturesize)
    Different values are obtained changing parameter "XXXXXX" for "MAX_720P", "LOWEST", "MAX_QVGA", etc., but the values I obtain do not correspond neither are proportional to the parameters For example, on my Asus Zenfone 2 I get a resolution of "4096x3072" for "MAX_480P", "MAX_720P", "MAX_1080P" and "MAX_QVGA", and "4096x3072" for "MAX_2160" and "HIGHEST". On a Vodafone Prime 6, some similar occurs: "352x288" for "LOWEST", "720x480" for "MAX_480P", "3264x1836" for "MAX_720P", "MAX_1080P", "MAX_2160P" and "HIGHEST", and "3264x2448" for "MAX_QVGA".

    How can it be set/controlled the right way?

    - The second one is preview size. In Portrait mode I haven't detected any problem, but in Landscape mode Preview is seen elongated vertically, although video is recorded right. I've tried to set camera layout proportional to resolution and fiot to screen, but no luck.

    Is there any way to control the preview dimensions?

    Thanks in advance.
     
    Rockefeller Goldman likes this.
  14. Shalu Samtani

    Shalu Samtani Member Licensed User

    im sorry, i can't find the image file in your example when snap picture
     
    Rockefeller Goldman likes this.
  15. DonManfred

    DonManfred Expert Licensed User

    onPictureTaken get a bytearray with the image. If you want to save it you need to do it manually.
     
    Rockefeller Goldman likes this.
  16. Rockefeller Goldman

    Rockefeller Goldman Active Member Licensed User

    Last edited: Mar 14, 2018
  17. nicolino33

    nicolino33 Active Member Licensed User

    Hello, one method for set picture size in CameraView ?
     
  18. DonManfred

    DonManfred Expert Licensed User

    Not that i know of / remember...
     
  19. nicolino33

    nicolino33 Active Member Licensed User

    eheheh.... I'v look.... it lacks an essential function! This library make photo at max resolution, and with new phone the dimension of photo an even exceed 10/11 mb. Is not possible to make a new implementation of picture size setting? maybe through in-line java, why this? why the time for take picture at max resolution are very long... you should also update the target sdk to 26.
     
    Last edited: Jul 18, 2018
  20. DonManfred

    DonManfred Expert Licensed User

    Feel free to use any other library!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice