English 中文(简体)
get image from iphone, using phonegap camera api
原标题:

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.

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.

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?

问题回答

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.

// 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.

both are the same function Camera.getPicture pamameter only differs 0 or 1, but photos also not wokring!

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?

I followed the example on PhoneGap s API documentation and it works for me using an iPhone 4 device. 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;
}




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签