将图像的内容从相机加载到文件 [英] Load contents of image from camera to a file

查看:159
本文介绍了将图像的内容从相机加载到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用phonegap API使用以下限制条件来拍摄照片(或从库中选择):

I am taking a picture (or selecting from library) using phonegap API using the following drictive:

MyApp.directive('Camera', function () {
    return {
        restrict: 'A',
        require: 'ngModel',
        link: function(scope, elm, attrs, ctrl) {
            elm.bind('click', function() {
                navigator.camera.getPicture(function (imageURI)
                {
                    scope.$apply(function() {
                        ctrl.$setViewValue(imageURI);
                    });
                }, function (err) {
                    ctrl.$setValidity('error', false);
                },
                //Options => http://docs.phonegap.com/en/2.6.0/cordova_camera_camera.md.html#Camera
                { quality: 50,
                  destinationType:Camera.DestinationType.FILE_URI                      
                })
            });
        }
    };
});

这会返回一个URI看起来像,使用chrome上的波纹模拟器,我看到粘贴URI。

Which return me a URI that looks like, using ripple emulator on chrome, which I cann see pasting this URI.

blob:http%3A//localhost%3A8080/8e18de30-d049-4ce2-ae88-8500b444581e

我的问题是加载此URI

My issue is loading this URI

$scope.updateUserProfile = function (user) {

       var myPicfile = $http.get(user.myPicture);

       dataService.uploadPicture . . . some code to update the picture to Parse

    }

*注意: a href =https://parse.com/questions/file-upload-returns-201-but-doesnt-seem-to-be-valid =nofollow noreferrer>我不能使用phonegap文件传输与解析。 com:

*Note: I cannot use phonegap filetransfer together with parse.com :

当我这样做时,我会得到:

When I do that I get:

我要求我的要求:

uploadPicture:function uploadPicture(user,callback)
{
var serverUrl =' https://api.parse.com/1/files/ '+ user.Nick;

uploadPicture: function uploadPicture(user,callback) { var serverUrl = 'https://api.parse.com/1/files/' + user.Nick ;

            $http({
                method: 'POST',
                url: serverUrl,
                data: user.myPicture,
                headers: {'X-Parse-Application-Id': PARSE_APP_ID,
                    'X-Parse-REST-API-Key': PARSE_REST_API_KEY,
                    'Content-Type': 'text/plain'
                }
            })

有关如何将图片内容提供给文件的任何想法,上传到Parse.com?

Any idea on how to get the content of the image to a file that then I can happily upload to Parse.com?

谢谢!

推荐答案

工作,因为我的最终目标是使用它与phonegap,并附上此信息中的信息。 。非常感谢Raymond Camden!

I finally work it around, since my ultimate goal was to use it with phonegap, with the info in this post. . Big thanks to Raymond Camden!

function gotPic(data) {

window.resolveLocalFileSystemURI(data, function(entry) {

var reader = new FileReader();

reader.onloadend = function(evt) {
    var byteArray = new Uint8Array(evt.target.result);
    var output = new Array( byteArray.length );
    var i = 0;
    var n = output.length;
    while( i < n ) {
        output[i] = byteArray[i];
        i++;
    }                
    var parseFile = new Parse.File("mypic.jpg", output);

    parseFile.save().then(function(ob) {
            navigator.notification.alert("Got it!", null);
            console.log(JSON.stringify(ob));
        }, function(error) {
            console.log("Error");
            console.log(error);
        });

}

reader.onerror = function(evt) {
      console.log('read error');
      console.log(JSON.stringify(evt));
  }

entry.file(function(s) {
    reader.readAsArrayBuffer(s);
}, function(e) {
    console.log('ee');
});

});
}

这篇关于将图像的内容从相机加载到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆