gpt4 book ai didi

javascript - Phonegap - 相机拍摄的照片总是变成风景

转载 作者:太空宇宙 更新时间:2023-11-04 11:51:56 27 4
gpt4 key购买 nike

我能够使用 phonegap 文件上传脚本成功上传照片。但问题是当我拍一张肖像照片并且它显示在缩略图中时,它会变成风景照片但是当你从图库中拿起它时它会显示原样

<script>



var deviceReady = false;

/**
* Take picture with camera
*/
function takePicture() {
navigator.camera.getPicture(
function(uri) {
var img = document.getElementById('camera_image');
img.style.visibility = "visible";
img.style.display = "block";
img.src = uri;
document.getElementById('camera_status').innerHTML = "Success";
},
function(e) {
console.log("Error getting picture: " + e);
document.getElementById('camera_status').innerHTML = "Error getting picture.";
},
{ quality: 50, destinationType: navigator.camera.DestinationType.FILE_URI});
};

/**
* Select picture from library
*/
function selectPicture() {
navigator.camera.getPicture(
function(uri) {
var img = document.getElementById('camera_image');
img.style.visibility = "visible";
img.style.display = "block";
img.src = uri;
document.getElementById('camera_status').innerHTML = "Success";
},
function(e) {
console.log("Error getting picture: " + e);
document.getElementById('camera_status').innerHTML = "Error getting picture.";
},
{ quality: 50, destinationType: navigator.camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY});
};

/**
* Upload current picture
*/
function uploadPicture() {

// Get URI of picture to upload
var img = document.getElementById('camera_image');
var imageURI = img.src;
if (!imageURI || (img.style.display == "none")) {
document.getElementById('camera_status').innerHTML = "Take picture or select picture from gallery";
return;
}

// Verify server has been entered
server = document.getElementById('serverUrl').value;
if (server) {

// Specify transfer options
var options = new FileUploadOptions();
randomizer = Math.floor((Math.random() * 1000000) + 1);
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1)+randomizer+'.jpg';
options.mimeType="image/jpeg";
options.chunkedMode = false;




options.params = {
filename: window.localStorage.setItem("key", options.fileName),


}


// Transfer picture to server
var ft = new FileTransfer();
ft.upload(imageURI, "http://myphonegap/pg_upload.php", function(r) {
document.getElementById('camera_status').innerHTML = "Please wait redirecting";
window.location.href = "source.html"
}, function(error) {
document.getElementById('camera_status').innerHTML = "Upload failed: Code = "+error.code;
}, options);
}
}

/**
* View pictures uploaded to the server
*/
function viewUploadedPictures() {

// Get server URL
server = document.getElementById('serverUrl').value;
if (server) {

// Get HTML that lists all pictures on server using XHR
var xmlhttp = new XMLHttpRequest();

// Callback function when XMLHttpRequest is ready
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState === 4){

// HTML is returned, which has pictures to display
if (xmlhttp.status === 200) {
document.getElementById('server_images').innerHTML = xmlhttp.responseText;
}

// If error
else {
document.getElementById('server_images').innerHTML = "Error retrieving pictures from server.";
}
}
};
xmlhttp.open("GET", server , true);
xmlhttp.send();
}
}

/**
* Function called when page has finished loading.
*/
function init() {
document.addEventListener("deviceready", function() {deviceReady = true;}, false);
window.setTimeout(function() {
if (!deviceReady) {
alert("Error: PhoneGap did not initialize. Demo will not run correctly.");
}
},2000);
}



</script>

最佳答案

您是否横向使用该应用?

如果是这样,请尝试在 getPicture() 函数中将此选项添加到相机设置中:

correctOrientation: false

或者如果您在肖像中使用,请尝试将其设置为 true。它闻起来像一个错误,但可能会修复它。

您是否也在检查实际上传的图片?方向错了吗?

关于javascript - Phonegap - 相机拍摄的照片总是变成风景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30571262/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com