locked
image size or ratio from tablets camera RRS feed

  • Question

  • I need to allow the user to crop the photo they shoot with a Windows 8.1 tablet camera and then display it in a <canvas> so that they can mark it up.  I want to grab the w x h ratio of the pic they shoot, then display it in the <canvas> w the same w x h ratio, so that it is not stretched horizontally or vertically,

    How do I grab the image w & h or w x h ratio?  Here is the code I am using to let the user shoot the photo.

    var captureUI = new Windows.Media.Capture.CameraCaptureUI();
    
    captureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.large3M;
    
    captureUI.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo).then(function (capturedItem) {...
    Thanks


    Phil

    Wednesday, March 19, 2014 11:54 PM

Answers

  • You can get the Properties from the returned StorageFile.
    • Marked as answer by pdschuller_ Thursday, March 20, 2014 12:13 PM
    Thursday, March 20, 2014 12:51 AM
    Moderator

All replies

  • You can get the Properties from the returned StorageFile.
    • Marked as answer by pdschuller_ Thursday, March 20, 2014 12:13 PM
    Thursday, March 20, 2014 12:51 AM
    Moderator
  • Thanks.  That got me pointed in the right direction.  Here's my solution. - not sure if its optimal.

    // see my code above for what capturedItem is var the_blob_url = URL.createObjectURL(capturedItem); var ii = new Image();

    ii.onload = function() {

    // you have to wait for the image to load, then you can grab the dimensions

    // ii.width is the width and ii.height is the height

    // do other stuff

    } ii.src = the_blob_url;


    ii.width = the width

    ii.height = the height


    Phil


    • Edited by pdschuller_ Thursday, March 20, 2014 3:16 PM added handling of async image load
    Thursday, March 20, 2014 12:12 PM