forked from public/cordova-plugin-camera
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e4ab155fd0 | |||
| f20703de20 | |||
| 543c4198d8 | |||
| 1650dce693 | |||
| 5b8324e984 | |||
| fa93b534d1 | |||
| c1683000d2 | |||
| 06ecc91fd1 | |||
| ffd46c4ef5 | |||
| 1cf38cd775 |
+7
-7
@@ -33,7 +33,7 @@ base64-encoded `String`, or as the URI for the image file. The method
|
||||
itself returns a `CameraPopoverHandle` object that can be used to
|
||||
reposition the file selection popover.
|
||||
|
||||
navigator.camera.getPicture( cameraSuccess, cameraError, [ cameraOptions ] );
|
||||
navigator.camera.getPicture( cameraSuccess, cameraError, cameraOptions );
|
||||
|
||||
### Description
|
||||
|
||||
@@ -169,9 +169,9 @@ Optional parameters to customize the camera settings.
|
||||
|
||||
### Options
|
||||
|
||||
- __quality__: Quality of the saved image, expressed as a range of 0-100, where 100 is typically full resolution with no loss from file compression. _(Number)_ (Note that information about the camera's resolution is unavailable.)
|
||||
- __quality__: Quality of the saved image, expressed as a range of 0-100, where 100 is typically full resolution with no loss from file compression. The default is 50. _(Number)_ (Note that information about the camera's resolution is unavailable.)
|
||||
|
||||
- __destinationType__: Choose the format of the return value. Defined in `navigator.camera.DestinationType` _(Number)_
|
||||
- __destinationType__: Choose the format of the return value. The default is FILE_URI. Defined in `navigator.camera.DestinationType` _(Number)_
|
||||
|
||||
Camera.DestinationType = {
|
||||
DATA_URL : 0, // Return image as base64-encoded string
|
||||
@@ -179,7 +179,7 @@ Optional parameters to customize the camera settings.
|
||||
NATIVE_URI : 2 // Return image native URI (e.g., assets-library:// on iOS or content:// on Android)
|
||||
};
|
||||
|
||||
- __sourceType__: Set the source of the picture. Defined in `navigator.camera.PictureSourceType` _(Number)_
|
||||
- __sourceType__: Set the source of the picture. The default is CAMERA. Defined in `navigator.camera.PictureSourceType` _(Number)_
|
||||
|
||||
Camera.PictureSourceType = {
|
||||
PHOTOLIBRARY : 0,
|
||||
@@ -189,7 +189,7 @@ Optional parameters to customize the camera settings.
|
||||
|
||||
- __allowEdit__: Allow simple editing of image before selection. _(Boolean)_
|
||||
|
||||
- __encodingType__: Choose the returned image file's encoding. Defined in `navigator.camera.EncodingType` _(Number)_
|
||||
- __encodingType__: Choose the returned image file's encoding. Default is JPEG. Defined in `navigator.camera.EncodingType` _(Number)_
|
||||
|
||||
Camera.EncodingType = {
|
||||
JPEG : 0, // Return JPEG encoded image
|
||||
@@ -214,7 +214,7 @@ Optional parameters to customize the camera settings.
|
||||
|
||||
- __popoverOptions__: iOS-only options that specify popover location in iPad. Defined in `CameraPopoverOptions`.
|
||||
|
||||
- __cameraDirection__: Choose the camera to use (front- or back-facing). Defined in `navigator.camera.Direction` _(Number)_
|
||||
- __cameraDirection__: Choose the camera to use (front- or back-facing). The default is BACK. Defined in `navigator.camera.Direction` _(Number)_
|
||||
|
||||
Camera.Direction = {
|
||||
BACK : 0, // Use the back-facing camera
|
||||
@@ -275,7 +275,7 @@ Optional parameters to customize the camera settings.
|
||||
|
||||
- Set `quality` below 50 to avoid memory errors on some devices.
|
||||
|
||||
- When using `destinationType.FILE_URI`, photos are saved in the application's temporary directory. You may delete the contents of this directory using the `navigator.fileMgr` APIs if storage space is a concern.
|
||||
- When using `destinationType.FILE_URI`, photos are saved in the application's temporary directory. The contents of the application's temporary directory is deleted when the application ends.
|
||||
|
||||
### Tizen Quirks
|
||||
|
||||
|
||||
+1
-2
@@ -22,7 +22,7 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:rim="http://www.blackberry.com/ns/widgets"
|
||||
id="org.apache.cordova.camera"
|
||||
version="0.3.0">
|
||||
version="0.3.1-dev">
|
||||
<name>Camera</name>
|
||||
<description>Cordova Camera Plugin</description>
|
||||
<license>Apache 2.0</license>
|
||||
@@ -202,7 +202,6 @@
|
||||
<!-- windows8 -->
|
||||
<platform name="windows8">
|
||||
|
||||
<dependency id="org.apache.cordova.file" />
|
||||
<config-file target="package.appxmanifest" parent="/Package/Capabilities">
|
||||
<Capability Name="picturesLibrary" />
|
||||
<DeviceCapability Name="webcam" />
|
||||
|
||||
Executable → Regular
+17
-12
@@ -380,14 +380,19 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
||||
else if (destType == FILE_URI || destType == NATIVE_URI) {
|
||||
if (this.saveToPhotoAlbum) {
|
||||
Uri inputUri = getUriFromMediaStore();
|
||||
//Just because we have a media URI doesn't mean we have a real file, we need to make it
|
||||
uri = Uri.fromFile(new File(FileHelper.getRealPath(inputUri, this.cordova)));
|
||||
try {
|
||||
//Just because we have a media URI doesn't mean we have a real file, we need to make it
|
||||
uri = Uri.fromFile(new File(FileHelper.getRealPath(inputUri, this.cordova)));
|
||||
} catch (NullPointerException e) {
|
||||
uri = null;
|
||||
}
|
||||
} else {
|
||||
uri = Uri.fromFile(new File(getTempDirectoryPath(), System.currentTimeMillis() + ".jpg"));
|
||||
}
|
||||
|
||||
if (uri == null) {
|
||||
this.failPicture("Error capturing image - no media storage found.");
|
||||
return;
|
||||
}
|
||||
|
||||
// If all this is true we shouldn't compress the image.
|
||||
@@ -420,14 +425,14 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
||||
exif.writeExifData();
|
||||
}
|
||||
if (this.allowEdit) {
|
||||
performCrop(uri);
|
||||
} else {
|
||||
// Send Uri back to JavaScript for viewing image
|
||||
this.callbackContext.success(uri.toString());
|
||||
}
|
||||
performCrop(uri);
|
||||
} else {
|
||||
// Send Uri back to JavaScript for viewing image
|
||||
this.callbackContext.success(uri.toString());
|
||||
}
|
||||
}
|
||||
// Send Uri back to JavaScript for viewing image
|
||||
this.callbackContext.success(uri.toString());
|
||||
} else {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
this.cleanup(FILE_URI, this.imageUri, uri, bitmap);
|
||||
@@ -641,7 +646,7 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
|
||||
|
||||
// If retrieving photo from library
|
||||
else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
if (resultCode == Activity.RESULT_OK && intent != null) {
|
||||
this.processResultFromGallery(destType, intent);
|
||||
}
|
||||
else if (resultCode == Activity.RESULT_CANCELED) {
|
||||
@@ -735,11 +740,11 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException {
|
||||
Uri uri;
|
||||
try {
|
||||
uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
|
||||
} catch (UnsupportedOperationException e) {
|
||||
} catch (RuntimeException e) {
|
||||
LOG.d(LOG_TAG, "Can't write to external media storage.");
|
||||
try {
|
||||
uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
|
||||
} catch (UnsupportedOperationException ex) {
|
||||
} catch (RuntimeException ex) {
|
||||
LOG.d(LOG_TAG, "Can't write to internal media storage.");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,6 @@ typedef NSUInteger CDVMediaType;
|
||||
* quality: integer between 1 and 100
|
||||
*/
|
||||
- (void)takePicture:(CDVInvokedUrlCommand*)command;
|
||||
- (void)postImage:(UIImage*)anImage withFilename:(NSString*)filename toUrl:(NSURL*)url;
|
||||
- (void)cleanup:(CDVInvokedUrlCommand*)command;
|
||||
- (void)repositionPopover:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
|
||||
@@ -533,48 +533,6 @@ static NSSet* org_apache_cordova_validArrowDirections;
|
||||
return newImage;
|
||||
}
|
||||
|
||||
- (void)postImage:(UIImage*)anImage withFilename:(NSString*)filename toUrl:(NSURL*)url
|
||||
{
|
||||
self.hasPendingOperation = YES;
|
||||
|
||||
NSString* boundary = @"----BOUNDARY_IS_I";
|
||||
|
||||
NSMutableURLRequest* req = [NSMutableURLRequest requestWithURL:url];
|
||||
[req setHTTPMethod:@"POST"];
|
||||
|
||||
NSString* contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
|
||||
[req setValue:contentType forHTTPHeaderField:@"Content-type"];
|
||||
|
||||
NSData* imageData = UIImagePNGRepresentation(anImage);
|
||||
|
||||
// adding the body
|
||||
NSMutableData* postBody = [NSMutableData data];
|
||||
|
||||
// first parameter an image
|
||||
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
|
||||
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"upload\"; filename=\"%@\"\r\n", filename] dataUsingEncoding:NSUTF8StringEncoding]];
|
||||
[postBody appendData:[@"Content-Type: image/png\r\n\r\n" dataUsingEncoding : NSUTF8StringEncoding]];
|
||||
[postBody appendData:imageData];
|
||||
|
||||
// // second parameter information
|
||||
// [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
|
||||
// [postBody appendData:[@"Content-Disposition: form-data; name=\"some_other_name\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
|
||||
// [postBody appendData:[@"some_other_value" dataUsingEncoding:NSUTF8StringEncoding]];
|
||||
// [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r \n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
|
||||
|
||||
[req setHTTPBody:postBody];
|
||||
|
||||
NSURLResponse* response;
|
||||
NSError* error;
|
||||
[NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];
|
||||
|
||||
// NSData* result = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];
|
||||
// NSString * resultStr = [[[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding] autorelease];
|
||||
|
||||
self.hasPendingOperation = NO;
|
||||
}
|
||||
|
||||
|
||||
- (CLLocationManager *)locationManager {
|
||||
|
||||
if (locationManager != nil) {
|
||||
|
||||
+37
-78
@@ -22,12 +22,8 @@
|
||||
/*global Windows:true, URL:true */
|
||||
|
||||
|
||||
|
||||
var cordova = require('cordova'),
|
||||
Camera = require('./Camera'),
|
||||
FileEntry = require('org.apache.cordova.file.FileEntry'),
|
||||
FileError = require('org.apache.cordova.file.FileError'),
|
||||
FileReader = require('org.apache.cordova.file.FileReader');
|
||||
var cordova = require('cordova'),
|
||||
Camera = require('./Camera');
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -54,13 +50,6 @@ module.exports = {
|
||||
var mediaType = args[6];
|
||||
var saveToPhotoAlbum = args[9];
|
||||
|
||||
var pkg = Windows.ApplicationModel.Package.current;
|
||||
var packageId = pkg.installedLocation;
|
||||
|
||||
var fail = function (fileError) {
|
||||
errorCallback("FileError, code:" + fileError.code);
|
||||
};
|
||||
|
||||
// resize method :)
|
||||
var resizeImage = function (file) {
|
||||
var tempPhotoFileName = "";
|
||||
@@ -69,64 +58,40 @@ module.exports = {
|
||||
} else {
|
||||
tempPhotoFileName = "camera_cordova_temp_return.jpg";
|
||||
}
|
||||
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');
|
||||
|
||||
canvas.width = imageWidth;
|
||||
canvas.height = imageHeight;
|
||||
|
||||
var ctx = canvas.getContext("2d");
|
||||
ctx.drawImage(this, 0, 0, imageWidth, imageHeight);
|
||||
|
||||
// The resized file ready for upload
|
||||
var _blob = canvas.msToBlob();
|
||||
var _stream = _blob.msDetachStream();
|
||||
|
||||
var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
|
||||
storageFolder.createFileAsync(tempPhotoFileName, Windows.Storage.CreationCollisionOption.generateUniqueName).done(function (file) {
|
||||
file.openAsync(Windows.Storage.FileAccessMode.readWrite).done(function (fileStream) {
|
||||
Windows.Storage.Streams.RandomAccessStream.copyAndCloseAsync(_stream, fileStream).done(function () {
|
||||
var _imageUrl = URL.createObjectURL(file);
|
||||
successCallback(_imageUrl);
|
||||
}, function () {
|
||||
errorCallback("Resize picture error.");
|
||||
});
|
||||
}, function () {
|
||||
errorCallback("Resize picture error.");
|
||||
});
|
||||
}, function () {
|
||||
errorCallback("Resize picture error.");
|
||||
});
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
reader.readAsDataURL(filePhoto);
|
||||
};
|
||||
|
||||
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, storageFile.path));
|
||||
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;
|
||||
|
||||
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 () {
|
||||
fail(FileError.INVALID_MODIFICATION_ERR);
|
||||
}, function () {
|
||||
errorCallback("Folder not access.");
|
||||
errorCallback("Can't access localStorage folder");
|
||||
});
|
||||
|
||||
};
|
||||
@@ -188,9 +153,7 @@ module.exports = {
|
||||
file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
|
||||
successCallback(URL.createObjectURL(storageFile));
|
||||
}, function () {
|
||||
fail(FileError.INVALID_MODIFICATION_ERR);
|
||||
}, function () {
|
||||
errorCallback("Folder not access.");
|
||||
errorCallback("Can't access localStorage folder.");
|
||||
});
|
||||
|
||||
}
|
||||
@@ -252,7 +215,7 @@ module.exports = {
|
||||
cameraCaptureUI.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo).then(function (picture) {
|
||||
if (picture) {
|
||||
// save to photo album successCallback
|
||||
var success = function (fileEntry) {
|
||||
var success = function () {
|
||||
if (destinationType == Camera.DestinationType.FILE_URI) {
|
||||
if (targetHeight > 0 && targetWidth > 0) {
|
||||
resizeImage(picture);
|
||||
@@ -262,9 +225,7 @@ module.exports = {
|
||||
picture.copyAsync(storageFolder, picture.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
|
||||
successCallback("ms-appdata:///local/" + storageFile.name);
|
||||
}, function () {
|
||||
fail(FileError.INVALID_MODIFICATION_ERR);
|
||||
}, function () {
|
||||
errorCallback("Folder not access.");
|
||||
errorCallback("Can't access localStorage folder.");
|
||||
});
|
||||
}
|
||||
} else {
|
||||
@@ -287,7 +248,7 @@ module.exports = {
|
||||
if (saveToPhotoAlbum) {
|
||||
Windows.Storage.StorageFile.getFileFromPathAsync(picture.path).then(function (storageFile) {
|
||||
storageFile.copyAsync(Windows.Storage.KnownFolders.picturesLibrary, picture.name, Windows.Storage.NameCollisionOption.generateUniqueName).then(function (storageFile) {
|
||||
success(storageFile);
|
||||
success();
|
||||
}, function () {
|
||||
fail();
|
||||
});
|
||||
@@ -304,9 +265,7 @@ module.exports = {
|
||||
picture.copyAsync(storageFolder, picture.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
|
||||
successCallback("ms-appdata:///local/" + storageFile.name);
|
||||
}, function () {
|
||||
fail(FileError.INVALID_MODIFICATION_ERR);
|
||||
}, function () {
|
||||
errorCallback("Folder not access.");
|
||||
errorCallback("Can't access localStorage folder.");
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user