Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
Posts: 281
Registered: ‎05-31-2012
My Device: Playbook
Accepted Solution

How to use the Camera?

Hi, how can I use the Camera?

 

In the API Reference I just find this:

https://developer.blackberry.com/html5/apis/blackberry.media.camera.html

 

and there are no functions listed how to start the camera und get a picture.

Plase "+Like" my post if it was helpful.
Developer
Posts: 322
Registered: ‎08-06-2012
My Device: Dev Alpha / Playbook / Curve 9300

Re: How to use the Camera?

I use the code below in one of my projects.  Its for Playbook.

 

In this code there are references to other libraries like Caman and a debug lib.  Just remove the code you dont want.  When fired, it will take a picture and then load the file into a canvas object.

 

function takePicture() {

    document.getElementById('actind').hide();

    try {
        debug.log("takePicture", "Start", debug.info);

        if ((window.blackberry === undefined) || (blackberry.media === undefined)) {
            debug.log("takePicture", "blackberry.media.camera object is undefined.", debug.error);
            return false;
        }

        debug.log("takePicture", "calling blackberry.media.camera.takePicture.", debug.info);
        var result = blackberry.media.camera.takePicture(onPhotoCaptured, onCameraClosed, onError);
    }
    catch (e) {
        debug.log("takePicture", e, debug.exception);
    }
}

function onCameraClosed(closedEvent) {
    debug.log("onCameraClosed", "Start: " + closedEvent, debug.info);
}

function onError(errorEvent) {
    alert("Error: " + errorEvent, debug.info);
}

function onPhotoCaptured(filePath) {
    try {
        var img;

        debug.log("onPhotoCaptured", "Start: " + filePath, debug.info);

        //For Smartphone, add "file://" prefix before path
        if (isBlackBerrySmartphone()) {
            filePath = "file://" + filePath;
        }

        img = new Image();
        img.width = Math.round(screen.width - 290);
        img.src=filePath;
        img.id = 'photo_canvas';
        img.setAttribute('data-camanwidth', screen.width - 290);
        img.setAttribute('data-camanheight', 490);

        document.getElementById("photoDetails").appendChild(img);

        Caman("#photo_canvas", function () {
            this.render();
        });

    }
    catch (e) {
        debug.log("onPhotoCaptured", e, debug.exception);
    }
}

 

If it helped you, click like. :smileyhappy:
Developer
Posts: 281
Registered: ‎05-31-2012
My Device: Playbook

Re: How to use the Camera?

Thank you very much
Plase "+Like" my post if it was helpful.