Class Camera


  • public class Camera
    extends java.lang.Object
    This class is used to enable the camera of the underlying device. The following platforms are supported: Windows Mobile devices, Blackberry, Palm OS, Android and iOS.

    For more information about the possible parameters on Windows, see: http://msdn2.microsoft.com/en-us/library/bb431794.aspx

    See the CameraTest sample.

    Note that you can easily rotate the image to put it in portrait mode, using the Image.getRotatedScaledInstance method, after retrieving the image.

    To use this class with the Hand Held Dolphin barcode scanners, you must install TotalCross3/dist/vm/wince/POCKETPC/ARM/Dolphin.dll. Only 640x480 photos are supported, and you may change the following options:

    • initialDir
    • defaultFileName (must end with jpg)
    • resolutionWidth x resolutionHeight: possible values are 640x480 and 212x160 (different values defaults to 640x480)
    All other options are ignored.

    In Android you can set the defaultFileName, stillQuality, resolutionWidth and resolutionHeight. All other options are ignored.

    You can call the getSupportedResolutions method to see the resolutions that are available at the device.

    In iOS there's no way to return the supported resolutions; it will take a photo using the default camera's resolution, and then will resize to the resolution defined in resolutionWidth/resolutionHeight, keeping the camera's aspect ratio. In iOS you can specify the defaultFileName with a path or just the name, or use a system-generated name.

    In Android, you can use the internal camera by setting the cameraType field.

    See Also:
    getSupportedResolutions()
    • Field Detail

      • initialDir

        public java.lang.String initialDir
        The initial directory.
      • defaultFileName

        public java.lang.String defaultFileName
        The default file name.
      • title

        public java.lang.String title
        The title to display in the window.
      • resolutionWidth

        public int resolutionWidth
        The width for the resolution
      • resolutionHeight

        public int resolutionHeight
        The height for the resolution
      • videoTimeLimit

        public int videoTimeLimit
        Maximum time limit for recording a video.
      • allowRotation

        public boolean allowRotation
        This field is false by default so that the default camera orientation is still landscape. If this is set to true, the camera orientation will follow the device orientation. Used on Android only.
      • cameraType

        public int cameraType
        The camera type; defaults to CAMERA_CUSTOM.
      • targetFps

        public int targetFps
        Expected FPS for the output file created with CAMERA_VIDEO_RECORDER.
      • bitrate

        public int bitrate
        Video bitrate in kbps. Adjust this field to increase or decrease the quality and the size of the output video.

        Quality is subjective and context related, therefore it's hard to define objective values. Higher resolutions also requires higher bitrates for better results.

        Values in the range of 100kbps (100_000) and 400kbps (400_000) should be enough for most videos up to HD resolution (1280x720 or CAMERACAPTURE_STILLQUALITY_NORMAL).

        Values in the range of 1mbps (1_000_000) and 3mpbs (3_000_000) will provide the best quality a huge output file.

      • CAMERA_CUSTOM

        public static final int CAMERA_CUSTOM
        The original camera used in TotalCross
        See Also:
        Constant Field Values
      • CAMERA_NATIVE

        public static final int CAMERA_NATIVE
        The native camera application; a copy of the image is returned.
        See Also:
        Constant Field Values
      • CAMERA_NATIVE_NOCOPY

        public static final int CAMERA_NATIVE_NOCOPY
        The native camera application; the original image is deleted and a copy of it is returned.
        See Also:
        Constant Field Values
      • CAMERA_FROM_GALLERY

        public static final int CAMERA_FROM_GALLERY
        Take the picture from the gallery.
        See Also:
        Constant Field Values
      • CAMERA_VIDEO_PLAYER

        public static final int CAMERA_VIDEO_PLAYER
        Start video player for the file from defaultFileName.
        See Also:
        Constant Field Values
      • CAMERA_VIDEO_RECORDER

        public static final int CAMERA_VIDEO_RECORDER
        Record video. Use the fields videoTimeLimit, targetFps and stillQuality to better control the result.
        See Also:
        Constant Field Values
      • CAMERACAPTURE_MODE_STILL

        public static final int CAMERACAPTURE_MODE_STILL
        Used in the cameraMode member.
        See Also:
        Constant Field Values
      • CAMERACAPTURE_MODE_VIDEOONLY

        public static final int CAMERACAPTURE_MODE_VIDEOONLY
        Used in the cameraMode member.
        See Also:
        Constant Field Values
      • CAMERACAPTURE_MODE_VIDEOWITHAUDIO

        public static final int CAMERACAPTURE_MODE_VIDEOWITHAUDIO
        Used in the cameraMode member.
        See Also:
        Constant Field Values
      • CAMERACAPTURE_STILLQUALITY_DEFAULT

        public static final int CAMERACAPTURE_STILLQUALITY_DEFAULT
        Used in the videoType member.
        See Also:
        Constant Field Values
      • CAMERACAPTURE_STILLQUALITY_LOW

        public static final int CAMERACAPTURE_STILLQUALITY_LOW
        Used in the videoType member.
        See Also:
        Constant Field Values
      • CAMERACAPTURE_STILLQUALITY_NORMAL

        public static final int CAMERACAPTURE_STILLQUALITY_NORMAL
        Used in the videoType member.
        See Also:
        Constant Field Values
      • CAMERACAPTURE_STILLQUALITY_HIGH

        public static final int CAMERACAPTURE_STILLQUALITY_HIGH
        Used in the videoType member.
        See Also:
        Constant Field Values
      • CAMERACAPTURE_VIDEOTYPE_ALL

        public static final int CAMERACAPTURE_VIDEOTYPE_ALL
        Used in the captureMode member.
        See Also:
        Constant Field Values
      • CAMERACAPTURE_VIDEOTYPE_STANDARD

        public static final int CAMERACAPTURE_VIDEOTYPE_STANDARD
        Used in the captureMode member.
        See Also:
        Constant Field Values
      • CAMERACAPTURE_VIDEOTYPE_MESSAGING

        public static final int CAMERACAPTURE_VIDEOTYPE_MESSAGING
        Used in the captureMode member.
        See Also:
        Constant Field Values
      • fcbTitle

        public static java.lang.String fcbTitle
        The default title when used in desktop
    • Constructor Detail

      • Camera

        public Camera()
    • Method Detail

      • click

        public java.lang.String click()
                               throws IOException
        Takes a photo based on the members set.
        Returns:
        The String with the file name where the image is located or null if the user canceled.
        Throws:
        IOException - if any other error occurs.
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • getSupportedResolutions

        public static java.lang.String[] getSupportedResolutions()
        Returns the resolutions that are supported by the device. Works for Windows CE, Blackberry and Android.

        When the information is not available, a default list is returned and the first element is set to "Default values:".

        If you take a photo and an image with a different resolution is returned, its because the selected resolution is not supported by the device.

        Values are always in LANDSCAPE.

        Since:
        TotalCross 1.3
      • getVideoResolutions

        public static java.lang.String[] getVideoResolutions()
        Returns the resolutions supported by the device for video recording using the back camera. Currently, it works only on Android, other platforms return the same results as getSupportedResolutions().

        When the information is not available, a default list is returned and the first element is set to "Default values:".

        Since:
        TotalCross 4.9.12