简体   繁体   English

捕获phonegap ios后保存图像

[英]save image after capture phonegap ios

I am developing IOS app using phonegap ... I used the default camera api so the user can take photo for his user profile pic. 我正在使用phonegap开发IOS应用程序...我使用了默认的相机api,因此用户可以为其用户个人资料照片拍照。

the function is working fine but my problem the image that the user capture it wont save on the system files so I can retrieve it in other pages 该功能运行正常,但是我的问题是用户捕获的图像不会保存在系统文件中,因此我可以在其他页面中检索它

here is my code 这是我的代码

var pictureSource;   // picture source
    var destinationType; // sets the format of returned value 

    // Wait for Cordova to connect with the device
    //
    document.addEventListener("deviceready",onDeviceReady,false);

    // Cordova is ready to be used!
    //
    function onDeviceReady() {
        pictureSource=navigator.camera.PictureSourceType;
        destinationType=navigator.camera.DestinationType;
    }

    // Called when a photo is successfully retrieved
    //
    function onPhotoDataSuccess(imageData) {
      // Uncomment to view the base64 encoded image data
      // console.log(imageData);

      // Get image handle
      //
      var smallImage = document.getElementById('smallImage');

      // Unhide image elements
      //
      smallImage.style.display = 'block';

      // Show the captured photo
      // The inline CSS rules are used to resize the image
      //
      smallImage.src = "data:image/jpeg;base64," + imageData;

    }

    // Called when a photo is successfully retrieved
    //
    function onPhotoURISuccess(imageURI) {
      // Uncomment to view the image file URI 
      // console.log(imageURI);

      // Get image handle
      //
      document.getElementById('smallImage').src='img/me2.jpg';
      var smallImage = 'img/me2.jpg';

      // Unhide image elements
      //
      smallImage.style.display = 'block';

      // Show the captured photo
      // The inline CSS rules are used to resize the image
      //
      smallImage.src = imageURI;
    }

    // A button will call this function
    //
    function capturePhoto() {
      // Take picture using device camera and retrieve image as base64-encoded string
      navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
        destinationType: destinationType.DATA_URL });
    }

    // A button will call this function
    //
    function capturePhotoEdit() {
      // Take picture using device camera, allow edit, and retrieve image as base64-encoded string  
      navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, allowEdit: true,
        destinationType: destinationType.DATA_URL });
    }

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

    // Called if something bad happens.
    // 
    function onFail(message) {
      alert('Failed because: ' + message);
    }

how I can override the file ("img/me2.jpg") after the user take the pic using the camera? 用户使用相机拍摄照片后,如何覆盖文件(“ img / me2.jpg”)?

You cannot override the img/me2.jpg because that file is in the application bundle. 您无法覆盖img / me2.jpg,因为该文件位于应用程序捆绑包中。

You have to save the captured image in the application data folder (eg using the PhoneGap's File API), then save the url in the localStorage from where you can retrieve it at any time. 您必须将捕获的图像保存在应用程序数据文件夹中(例如,使用PhoneGap的File API),然后将URL保存在localStorage中,您可以随时从该位置检索它。

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

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