简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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