最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Phonegap return current orientation during image capture - Stack Overflow

programmeradmin2浏览0评论

I can only find information in their docs about the Accelerometer for returning device orientation. Is there anyway phonegap can return what way the device was being held when a picture was taken? To use the camera, I do this:

function capturePhoto() {
    // Take picture using device camera and retrieve image as base64-encoded string
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
        destinationType: destinationType.DATA_URL });
}

When it returns successful, it does this.

 function onPhotoDataSuccess(imageData) {
        var baseImg = imageData;
        $('#uploadPreUpImgSwapHtml').html('<img src="data:image/jpeg;base64,'+ baseImg +'" style="max-width:100%; width:auto; max-height:300px; height:auto;" / >');
        $('#uploadPreBaseDataSwapHtml').html('<input type="hidden" id="chosenPictureData" value="'+ baseImg +'" />');
        $('#uploadPictureBtnHideHtml').fadeIn();

    }

Is there a callback to the success that returns what way the device was being held while the picture was taken so I can send it to my upload file and rotate the picture correctly?

I can only find information in their docs about the Accelerometer for returning device orientation. Is there anyway phonegap can return what way the device was being held when a picture was taken? To use the camera, I do this:

function capturePhoto() {
    // Take picture using device camera and retrieve image as base64-encoded string
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
        destinationType: destinationType.DATA_URL });
}

When it returns successful, it does this.

 function onPhotoDataSuccess(imageData) {
        var baseImg = imageData;
        $('#uploadPreUpImgSwapHtml').html('<img src="data:image/jpeg;base64,'+ baseImg +'" style="max-width:100%; width:auto; max-height:300px; height:auto;" / >');
        $('#uploadPreBaseDataSwapHtml').html('<input type="hidden" id="chosenPictureData" value="'+ baseImg +'" />');
        $('#uploadPictureBtnHideHtml').fadeIn();

    }

Is there a callback to the success that returns what way the device was being held while the picture was taken so I can send it to my upload file and rotate the picture correctly?

Share Improve this question asked Oct 3, 2012 at 2:01 user1053263user1053263 7422 gold badges16 silver badges33 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 23

To make your life easier you can just call:

navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
    destinationType: destinationType.FILE_URI, 
    correctOrientation: true });

then you'll get a file that is rotated properly.

发布评论

评论列表(0)

  1. 暂无评论