从iPhone获取图像,使用phonegap相机api
我是Xcode和iPhone应用程序的新手。我想从iPhone(相机或库)中选择一个图像并通过ajax发送给php。从iPhone获取图像,使用phonegap相机api
http://wiki.phonegap.com/iPhone:-Camera-API
我使用的PhoneGap框架,Xcode的iPhone SDK版本3.1.x.点击按钮时,它会调用参数0或1的函数,但不会初始化摄像头或显示库。
我检查了模拟器的虚拟手机;没有相机的图标,但图片专辑在那里。
我使用了与上述链接相同的代码。
我该怎么做,什么以及如何检查?使用phonegap获取照片的任何其他功能?
它在调试控制台中显示此错误: 2010-03-25 23:36:02.337 PhoneGap [7433:207] Camera.getPicture:相机不可用。
两者都是相同的功能Camera.getPicture的pamameter只有不同的0或1,但照片也没有wokring!
相机在iPhone模拟器中不可用。在iPhone模拟器中运行时使用相册进行测试,然后在实际的iPhone设备上测试相机。
也不适用于我在实际的电话。被称为成功或失败的功能。我在getPicture周围放了一个try/catch,并且它捕获了一个异常,说“异常得到图片:ReferenceError:找不到变量:GapCam”。这在模拟器和手机上是一样的。任何想法?
我遵循了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;
}
很好...谢谢... – Mrunal 2013-04-02 16:23:05
// 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="" />
不错的一个...谢谢 – Mrunal 2013-04-02 16:22:46
您好,是否有可能嵌入摄像头一个div? – 2013-06-04 05:56:20