简体   繁体   English

使用phonegap相机api从iPhone获取图像

[英]get image from iphone, using phonegap camera api

I'm new to Xcode and iPhone apps. 我是Xcode和iPhone应用程序的新手。 I want to select an image from iPhone (camera or library) and send to php via ajax. 我想从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. 我正在使用phonegap框架Xcode iPhone SDK版本3.1.x。 On clicking button it calls function with parameter 0 or 1, but it does not initialize camera or display the library. 单击按钮时,它将使用参数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获取照片的功能吗?

The camera is not available in the iPhone Simulator. 该相机在iPhone Simulator中不可用。 Test with the Photo Album when running in the iPhone Simulator, and test the camera on an actual iPhone device. 在iPhone模拟器中运行时使用相册进行测试,并在实际的iPhone设备上测试相机。

// 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="" />

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:相机不可用。

both are the same function Camera.getPicture pamameter only differs 0 or 1, but photos also not wokring! 两者都是相同的功能Camera.getPicture参数仅相差0或1,但照片也不起作用!

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". 我对getPicture进行了一次try / catch,它捕获了一个异常,内容为“异常获取图片:ReferenceError:找不到变量:GapCam”。 This is the same on the simulator and the phone. 在模拟器和手机上也是如此。 Any idears? 有想法吗?

I followed the example on PhoneGap's API documentation and it works for me using an iPhone 4 device. 我遵循了PhoneGap的API文档中的示例,该示例适用于iPhone 4设备。 Here's my code: 这是我的代码:

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM