mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
Updated camera module to support full size images (Android) and custom size images.
This commit is contained in:
@ -10,19 +10,39 @@ class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePic
|
||||
|
||||
private _callback: (result?: imageSource.ImageSource) => void;
|
||||
|
||||
private _width: number;
|
||||
private _height: number;
|
||||
|
||||
public initWithCallback(callback: (result?: imageSource.ImageSource) => void): UIImagePickerControllerDelegateImpl {
|
||||
this._callback = callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
public initWithCallbackWidthAndHeight(callback: (result?: imageSource.ImageSource) => void, width, height): UIImagePickerControllerDelegateImpl {
|
||||
this._callback = callback;
|
||||
this._width = width;
|
||||
this._height = height;
|
||||
return this;
|
||||
}
|
||||
|
||||
imagePickerControllerDidFinishPickingMediaWithInfo(picker, info): void {
|
||||
if (info) {
|
||||
var source = info.valueForKey(UIImagePickerControllerOriginalImage);
|
||||
if (source) {
|
||||
var image = imageSource.fromNativeSource(source);
|
||||
var image = null;
|
||||
if (this._width || this._height) {
|
||||
console.log("Image resized!!!");
|
||||
var newSize = CGSizeMake(this._width, this._height);
|
||||
UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0);
|
||||
source.drawInRect(CGRectMake(0, 0, newSize.width, newSize.height));
|
||||
image = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
}
|
||||
|
||||
var imageSourceResult = image ? imageSource.fromNativeSource(image) : imageSource.fromNativeSource(source);
|
||||
|
||||
if (this._callback) {
|
||||
this._callback(image);
|
||||
this._callback(imageSourceResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -34,10 +54,18 @@ class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePic
|
||||
}
|
||||
}
|
||||
|
||||
export var takePicture = function (): Promise<imageSource.ImageSource> {
|
||||
export var takePicture = function (width?, height?): Promise<imageSource.ImageSource> {
|
||||
return new Promise<imageSource.ImageSource>((resolve, reject) => {
|
||||
var imagePickerController = new UIImagePickerController();
|
||||
var listener = UIImagePickerControllerDelegateImpl.new().initWithCallback(resolve);
|
||||
var listener = null;
|
||||
var reqWidth = width || 0;
|
||||
var reqHeight = height || reqWidth;
|
||||
if (reqWidth && reqHeight) {
|
||||
listener = UIImagePickerControllerDelegateImpl.new().initWithCallbackWidthAndHeight(resolve, reqWidth, reqHeight);
|
||||
}
|
||||
else {
|
||||
listener = UIImagePickerControllerDelegateImpl.new().initWithCallback(resolve);
|
||||
}
|
||||
imagePickerController.delegate = listener;
|
||||
|
||||
if (UIDevice.currentDevice().model !== "iPhone Simulator") {
|
||||
|
Reference in New Issue
Block a user