xcode 使用phonegap相机api从iphone获取图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2517792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
get image from iphone, using phonegap camera api
提问by udhaya
I'm new to Xcode and iPhone apps. I want to select an image from iPhone (camera or library) and send to php via ajax.
我是 Xcode 和 iPhone 应用程序的新手。我想从 iPhone(相机或库)中选择一个图像并通过 ajax 发送到 php。
http://wiki.phonegap.com/iPhone:-Camera-API
http://wiki.phonegap.com/iPhone:-Camera-API
I'm using the phonegap framework, Xcode iPhone SDK version 3.1.x. On clicking button it calls function with parameter 0 or 1, but it does not initialize camera or display the library.
我正在使用 phonegap 框架,Xcode iPhone SDK 版本 3.1.x。单击按钮时,它会调用参数为 0 或 1 的函数,但不会初始化相机或显示库。
I checked the simulator virtual phone; there is no icon for camera, but the pictures album is there.
我检查了模拟器虚拟电话;没有相机图标,但有相册。
I used the same code as in the above link.
我使用了与上面链接中相同的代码。
What do I do, what and how to check? any other functions to get photos using phonegap?
我该怎么做,检查什么以及如何检查?使用phonegap获取照片的任何其他功能?
回答by cdespinosa
The camera is not available in the iPhone Simulator. Test with the Photo Album when running in the iPhone Simulator, and test the camera on an actual iPhone device.
相机在 iPhone 模拟器中不可用。在 iPhone 模拟器中运行时使用相册进行测试,并在实际的 iPhone 设备上测试相机。
回答by casey
// JavaScript Document //Get Picture stuff
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, destinationType: destinationType.FILE_URI, sourceType:Camera.PictureSourceType.SAVEDPHOTOALBUM});
var pictureSource; // picture source
var destinationType; // sets the format of returned value
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
function onPhotoURISuccess(imageURI) {
// Uncomment to view the image file URI
console.log(imageURI);
// Get image handle
var largeImage = document.getElementById('largeImage');
// Unhide image elements
largeImage.style.display = 'block';
// Show the captured photo
// The inline CSS rules are used to resize the image
largeImage.src = imageURI;
}
// Called if something bad happens.
function onFail(message) {alert('Failed because: ' + message);
}
// put in index.html <img style="display:none;" id="largeImage" src="" />
回答by udhaya
it shows this error in debug console: 2010-03-25 23:36:02.337 PhoneGap[7433:207] Camera.getPicture: Camera not available.
它在调试控制台中显示此错误:2010-03-25 23:36:02.337 PhoneGap[7433:207] Camera.getPicture: Camera not available。
both are the same function Camera.getPicture pamameter only differs 0 or 1, but photos also not wokring!
两者都是相同的功能 Camera.getPicture pamameter 仅相差 0 或 1,但照片也不工作!
回答by Jay
does not work from me on the actual phone either. Neither success or fail functions are called. I put a try/catch around getPicture, and it catches an exception saying "exception getting picture: ReferenceError: Can't find variable: GapCam". This is the same on the simulator and the phone. Any idears?
在我的实际手机上也不起作用。成功或失败函数都不会被调用。我在 getPicture 周围放了一个 try/catch,它捕获了一个异常,说“异常获取图片:ReferenceError:找不到变量:GapCam”。这在模拟器和手机上都是一样的。有什么想法吗?
回答by Johnny Oshika
I followed the example on PhoneGap's API documentation and it works for me using an iPhone 4 device. Here's my code:
我按照 PhoneGap 的 API 文档中的示例进行操作,它适用于我使用 iPhone 4 设备的情况。这是我的代码:
function take_pic(){
var viewport = document.getElementById('viewport');
viewport.style.display = "";
navigator.camera.getPicture(dump_pic, fail, { quality: 50 });
}
function dump_pic(data){
var viewport = document.getElementById('viewport');
console.log(data);
viewport.style.display = "block";
viewport.style.position = "absolute";
viewport.style.top = "10px";
viewport.style.left = "10px";
document.getElementById("test_img").src = "data:image/jpeg;base64," + data;
}