diff --git a/doc/index.md b/doc/index.md
index edd881f..e892620 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -92,13 +92,6 @@ scenario, the image may not appear when the cordova activity is restored.
### Android Quirks
-*Android 4.4 only*: Android 4.4 introduced a new [Storage Access Framework](https://developer.android.com/guide/topics/providers/document-provider.html) that makes it
-easier for users to browse and open documents across all of their preferred document storage providers.
-Cordova has not yet been fully integrated with this new Storage Access Framework. Because of this, the `getPicture()`
-method will not correctly return pictures when the user selects from the "Recent", "Drive", "Images", or "External
-Storage" folders when the `destinationType` is `FILE_URI`. However, the user will be able to correctly select any pictures
-if they go through the "Gallery" app first. Potential workarounds for this issue are documented on [this StackOverflow question](http://stackoverflow.com/questions/19834842/android-gallery-on-kitkat-returns-different-uri-for-intent-action-get-content/20177611). Please see [CB-5398](https://issues.apache.org/jira/browse/CB-5398) to track this issue.
-
Android uses intents to launch the camera activity on the device to capture
images, and on phones with low memory, the Cordova activity may be killed. In this
scenario, the image may not appear when the Cordova activity is restored.
@@ -213,7 +206,7 @@ Optional parameters to customize the camera settings.
PICTURE: 0, // allow selection of still pictures only. DEFAULT. Will return format specified via DestinationType
VIDEO: 1, // allow selection of video only, WILL ALWAYS RETURN FILE_URI
ALLMEDIA : 2 // allow selection from all media types
-};
+ };
- __correctOrientation__: Rotate the image to correct for the orientation of the device during capture. _(Boolean)_
diff --git a/src/windows8/CameraProxy.js b/src/windows8/CameraProxy.js
index d46553b..9f21c44 100644
--- a/src/windows8/CameraProxy.js
+++ b/src/windows8/CameraProxy.js
@@ -133,55 +133,34 @@ module.exports = {
// because of asynchronous method, so let the successCallback be called in it.
var resizeImageBase64 = function (file) {
- var imgObj = new Image();
- var success = function (fileEntry) {
- var successCB = function (filePhoto) {
- var fileType = file.contentType,
- reader = new FileReader();
- reader.onloadend = function () {
- var image = new Image();
- image.src = reader.result;
- image.onload = function () {
- var imageWidth = targetWidth,
- imageHeight = targetHeight;
- var canvas = document.createElement('canvas');
+ Windows.Storage.FileIO.readBufferAsync(file).done( function(buffer) {
+ var strBase64 = Windows.Security.Cryptography.CryptographicBuffer.encodeToBase64String(buffer);
+ var imageData = "data:" + file.contentType + ";base64," + strBase64;
- canvas.width = imageWidth;
- canvas.height = imageHeight;
+ var image = new Image();
+ image.src = imageData;
- var ctx = canvas.getContext("2d");
- ctx.drawImage(this, 0, 0, imageWidth, imageHeight);
+ image.onload = function() {
+ var imageWidth = targetWidth,
+ imageHeight = targetHeight;
+ var canvas = document.createElement('canvas');
- // The resized file ready for upload
- var finalFile = canvas.toDataURL(fileType);
+ canvas.width = imageWidth;
+ canvas.height = imageHeight;
- // Remove the prefix such as "data:" + contentType + ";base64," , in order to meet the Cordova API.
- var arr = finalFile.split(",");
- var newStr = finalFile.substr(arr[0].length + 1);
- successCallback(newStr);
- };
- };
+ var ctx = canvas.getContext("2d");
+ ctx.drawImage(this, 0, 0, imageWidth, imageHeight);
- reader.readAsDataURL(filePhoto);
+ // The resized file ready for upload
+ var finalFile = canvas.toDataURL(file.contentType);
+ // Remove the prefix such as "data:" + contentType + ";base64," , in order to meet the Cordova API.
+ var arr = finalFile.split(",");
+ var newStr = finalFile.substr(arr[0].length + 1);
+ successCallback(newStr);
};
- var failCB = function () {
- errorCallback("File not found.");
- };
- fileEntry.file(successCB, failCB);
- };
-
- var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
- file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
- success(new FileEntry(storageFile.name, "ms-appdata:///local/" + storageFile.name));
- }, function () {
- fail(FileError.INVALID_MODIFICATION_ERR);
- }, function () {
- errorCallback("Folder not access.");
});
-
-
};
if (sourceType != Camera.PictureSourceType.CAMERA) {
diff --git a/src/wp/Camera.cs b/src/wp/Camera.cs
index b76929b..30bb5e8 100644
--- a/src/wp/Camera.cs
+++ b/src/wp/Camera.cs
@@ -343,18 +343,8 @@ namespace WPCordovaClassLib.Cordova.Commands
try
{
- //use photo's actual width & height if user doesn't provide width & height
- if (cameraOptions.TargetWidth < 0 && cameraOptions.TargetHeight < 0)
- {
- int streamLength = (int)stream.Length;
- imageContent = new byte[streamLength + 1];
- stream.Read(imageContent, 0, streamLength);
- }
- else
- {
- // resize photo
- imageContent = ResizePhoto(stream);
- }
+ // Resize photo and convert to JPEG
+ imageContent = ResizePhoto(stream);
}
finally
{
@@ -368,7 +358,6 @@ namespace WPCordovaClassLib.Cordova.Commands
/// Resize image
///
/// Image stream
- /// File data
/// resized image
private byte[] ResizePhoto(Stream stream)
{
@@ -382,10 +371,22 @@ namespace WPCordovaClassLib.Cordova.Commands
WriteableBitmap objWB = new WriteableBitmap(objBitmap);
objBitmap.UriSource = null;
- //Keep proportionally
- double ratio = Math.Min((double)cameraOptions.TargetWidth / objWB.PixelWidth, (double)cameraOptions.TargetHeight / objWB.PixelHeight);
- int width = Convert.ToInt32(ratio * objWB.PixelWidth);
- int height = Convert.ToInt32(ratio * objWB.PixelHeight);
+ // Calculate resultant image size
+ int width, height;
+ if (cameraOptions.TargetWidth >= 0 && cameraOptions.TargetHeight >= 0)
+ {
+ // Keep proportionally
+ double ratio = Math.Min(
+ (double)cameraOptions.TargetWidth / objWB.PixelWidth,
+ (double)cameraOptions.TargetHeight / objWB.PixelHeight);
+ width = Convert.ToInt32(ratio * objWB.PixelWidth);
+ height = Convert.ToInt32(ratio * objWB.PixelHeight);
+ }
+ else
+ {
+ width = objWB.PixelWidth;
+ height = objWB.PixelHeight;
+ }
//Hold the result stream
using (MemoryStream objBitmapStreamResized = new MemoryStream())