Choose Image From Gallery

Can anyone tell me, or point me in the direction of how to get an image from the phone's image gallery in Phonegap / Android? There's docs on accessing the camera (which works great) but not selecting an existing image.

I'm looking for Phonegap / Javascript rather than Java.

Thanks in advance!


Erm, the Camera docs cover this. Is this not working for you? Check out Camera.PictureSourceType for details. The docs site givens this example for deriving an image thus:

function getPhoto(source) {
  // Retrieve image file location from specified source
  navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
    destinationType: destinationType.FILE_URI,
    sourceType: source });
}

sourceType is the crucial bit here. It can be Camera.PictureSourceType.CAMERA (the default), or more useful for you it can be Camera.PictureSourceType.PHOTOLIBRARY or Camera.PictureSourceType.SAVEDPHOTOALBUM .

Camera Documentation


你也可以使用下面的库:https://github.com/wymsee/cordova-imagePicker我更喜欢这个,因为它更小,易于实现,并且不需要相机许可。


Take a look at this post, it may help you.

Sometimes, you may face some problem with uploading an existing image. The solution is simple, per this answer. Briefly, you need to convert the native Android URI to one that the API can use:

// URL you are trying to upload from inside gallery
window.resolveLocalFileSystemURI(img.URI, function(entry) {
  console.log(entry.fullPath);
  }, function(evt){
    console.log(evt.code);
  }
);
链接地址: http://www.djcxy.com/p/27038.html

上一篇: 用手机将图像保存到画廊中

下一篇: 从图库中选择图片