How to use the camera example?

edited April 2015 in UC Berkeley CS160

I'm trying to add photo-taking capabilities to my application, in javascript. I was told today during the Project Workshop during lecture to use this example as a guideline -->

However, when I open this application on the iPhone, it starts out thinking that it is horizontally oriented. How do I change it so that it is vertically oriented? (Here is an image for reference: )

******* EDIT I DID IT! There's a section called "onDeviceOrientationChange" where they set the orientation for the phone. I fiddled around with the degrees it was rotated to combat it.

My NEXT question would be.....where is the photo saved??? And how would I implement an action to save it locally to my device (either Mac or iPhone)?

I think I have where it would be saved, narrowed down to this chunk of code. But I'm still not too sure what to do with it...You can see me playing around with the "mac" exclusive platform, since we will probably be demoing on a mac.


  • Hello -

    The KPR Camera sample app saves captured photos into the platform media library on Mac OS, Android and iOS. As you pointed out, this is the code that saves the photo:

    var message = new Message("xkpr://library/pictures/save");
    message.requestChunk = chunk;   // the JPEG photo chunk corresponding to the captured image
    message.method = "POST"
    container.invoke(message, Message.CHUNK);

    This means that the photo is saved to your "Camera Roll" on iOS.

    There is actually code right below that shows how to save the image somewhere else locally:

    Files.deleteFile( );
    Files.writeChunk(, chunk );

    So for example, if you wanted to save the photo into the temporary items directory (replacing the existing photo), you'd do something like this:

    var uri = mergeURI(Files.temporaryDirectory, "photo.jpg");
    Files.deleteFile( uri );
    Files.writeChunk(uri, chunk );

    Regards, Brian

  • Thank you very much! With what you posted and the information found in the API documentation about files ( I managed to write the pictures to a folder in the application. :)

    (For others who are curious, application.url accesses your current application - so if you had

    var uri = mergeURI(application.url, "pictures/photo.jpg");

    It would save the photo into a folder called pictures in your application structure with the name of "photo.jpg".)

Sign In or Register to comment.