cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vladimir-kotikov <...@git.apache.org>
Subject [GitHub] cordova-plugin-camera pull request: CB-8706, CB-8707 saveToPhotoAl...
Date Mon, 30 Mar 2015 09:54:20 GMT
Github user vladimir-kotikov commented on a diff in the pull request:

    https://github.com/apache/cordova-plugin-camera/pull/78#discussion_r27377731
  
    --- Diff: src/windows/CameraProxy.js ---
    @@ -43,399 +43,468 @@ module.exports = {
         // 11 cameraDirection:0
     
         takePicture: function (successCallback, errorCallback, args) {
    -        var encodingType = args[5];
    -        var targetWidth = args[3];
    -        var targetHeight = args[4];
             var sourceType = args[2];
    -        var destinationType = args[1];
    -        var mediaType = args[6];
    -        var allowCrop = !!args[7];
    -        var saveToPhotoAlbum = args[9];
    -        var cameraDirection = args[11];
    -
    -        // resize method :)
    -        var resizeImage = function (file) {
    -            var tempPhotoFileName = "";
    -            if (encodingType == Camera.EncodingType.PNG) {
    -                tempPhotoFileName = "camera_cordova_temp_return.png";
    -            } else {
    -                tempPhotoFileName = "camera_cordova_temp_return.jpg";
    -            }
    -
    -            var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
    -            file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function
(storageFile) {
    -                Windows.Storage.FileIO.readBufferAsync(storageFile).then(function(buffer)
{
    -                    var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
    -                    var imageData = "data:" + file.contentType + ";base64," + strBase64;
    -                    var image = new Image();
    -                    image.src = imageData;
    -                    image.onload = function() {
    -                        var imageWidth = targetWidth,
    -                            imageHeight = targetHeight;
    -                        var canvas = document.createElement('canvas');
    -
    -                        canvas.width = imageWidth;
    -                        canvas.height = imageHeight;
     
    -                        canvas.getContext("2d").drawImage(this, 0, 0, imageWidth, imageHeight);
    -
    -                        var fileContent = canvas.toDataURL(file.contentType).split(',')[1];
    -
    -                        var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
    +        if (sourceType != Camera.PictureSourceType.CAMERA) {
    +            takePictureFromFile(successCallback, errorCallback, args);
    +        } else {
    +            takePictureFromCamera(successCallback, errorCallback, args);
    +        }
    +    }
    +};
     
    -                        storageFolder.createFileAsync(tempPhotoFileName, Windows.Storage.CreationCollisionOption.generateUniqueName).done(function
(storagefile) {
    -                            var content = Windows.Security.Cryptography.CryptographicBuffer.decodeFromBase64String(fileContent);
    -                            Windows.Storage.FileIO.writeBufferAsync(storagefile, content).then(function
() {
    -                                successCallback("ms-appdata:///local/" + storagefile.name);
    -                            }, function () {
    -                                errorCallback("Resize picture error.");
    -                            });
    -                        });
    -                    };
    -                });
    -            }, function () {
    -                errorCallback("Can't access localStorage folder");
    -            });
     
    -        };
    +// Resize method
    +function resizeImage(successCallback, errorCallback, file, targetWidth, targetHeight,
encodingType) {
    +    var tempPhotoFileName = "";
    +    if (encodingType == Camera.EncodingType.PNG) {
    +        tempPhotoFileName = "camera_cordova_temp_return.png";
    +    } else {
    +        tempPhotoFileName = "camera_cordova_temp_return.jpg";
    +    }
     
    -        // because of asynchronous method, so let the successCallback be called in it.
    -        var resizeImageBase64 = function (file) {
    +    var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
    +    file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting)
    +        .then(function (storageFile) { return Windows.Storage.FileIO.readBufferAsync(storageFile);
})
    +        .then(function(buffer) {
    +            var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
    +            var imageData = "data:" + file.contentType + ";base64," + strBase64;
    +            var image = new Image();
    +            image.src = imageData;
    +            image.onload = function() {
    +                var imageWidth = targetWidth,
    +                    imageHeight = targetHeight;
    +                var canvas = document.createElement('canvas');
    +                var storageFileName;
    +
    +                canvas.width = imageWidth;
    +                canvas.height = imageHeight;
    +
    +                canvas.getContext("2d").drawImage(this, 0, 0, imageWidth, imageHeight);
    +
    +                var fileContent = canvas.toDataURL(file.contentType).split(',')[1];
    +
    +                var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
    +
    +                storageFolder.createFileAsync(tempPhotoFileName, Windows.Storage.CreationCollisionOption.generateUniqueName)
    +                    .then(function (storagefile) {
    +                        var content = Windows.Security.Cryptography.CryptographicBuffer.decodeFromBase64String(fileContent);
    +                        storageFileName = storagefile.name;
    +                        return Windows.Storage.FileIO.writeBufferAsync(storagefile, content);
    +                    })
    +                    .done(function () {
    +                        successCallback("ms-appdata:///local/" + storageFileName);
    +                    }, errorCallback);
    +            };
    +        })
    +        .done(null, function(err) {
    +            errorCallback(err);
    +        }
    +    );
    +}
     
    -            Windows.Storage.FileIO.readBufferAsync(file).done( function(buffer) {
    -                var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
    -                var imageData = "data:" + file.contentType + ";base64," + strBase64;
    +// Because of asynchronous method, so let the successCallback be called in it.
    +function resizeImageBase64(successCallback, errorCallback, file, targetWidth, targetHeight)
{
    +    Windows.Storage.FileIO.readBufferAsync(file).done( function(buffer) {
    +        var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
    +        var imageData = "data:" + file.contentType + ";base64," + strBase64;
     
    -                var image = new Image();
    -                image.src = imageData;
    +        var image = new Image();
    --- End diff --
    
    Not sure if this is in scope of this PR but we may want to rewrite resize functionality
using classes from [Windows.Graphics.Imaging namespace](https://msdn.microsoft.com/en-us/library/windows/apps/br211940.aspx).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


Mime
View raw message