@@ -180,18 +180,6 @@ export class Asset extends SelectedAsset {
180
180
return this . _thumb ;
181
181
}
182
182
183
- getImage ( options ?: ImageOptions ) : Promise < image_source . ImageSource > {
184
- return new Promise < image_source . ImageSource > ( ( resolve , reject ) => {
185
-
186
- } ) ;
187
- }
188
-
189
- getImageData ( ) : Promise < ArrayBuffer > {
190
- return new Promise < ArrayBuffer > ( ( resolve , reject ) => {
191
-
192
- } ) ;
193
- }
194
-
195
183
get selected ( ) : boolean {
196
184
return ! ! this . _selected ;
197
185
}
@@ -299,11 +287,52 @@ class ImagePickerPH extends ImagePicker {
299
287
}
300
288
301
289
createPHImageThumb ( target , asset : PHAsset ) : void {
302
- PHImageManager . defaultManager ( ) . requestImageForAssetTargetSizeContentModeOptionsResultHandler ( asset , this . _thumbRequestSize , PHImageContentMode . PHImageContentModeAspectFill , this . _thumbRequestOptions , function ( target , uiImage , info ) {
303
- var imageSource = new image_source . ImageSource ( ) ;
304
- imageSource . setNativeSource ( uiImage ) ;
305
- target . setThumb ( imageSource ) ;
306
- } . bind ( this , target ) ) ;
290
+ PHImageManager . defaultManager ( ) . requestImageForAssetTargetSizeContentModeOptionsResultHandler ( asset , this . _thumbRequestSize , PHImageContentMode . PHImageContentModeAspectFill ,
291
+ this . _thumbRequestOptions , function ( target , uiImage , info ) {
292
+ var imageSource = new image_source . ImageSource ( ) ;
293
+ imageSource . setNativeSource ( uiImage ) ;
294
+ target . setThumb ( imageSource ) ;
295
+ } . bind ( this , target ) ) ;
296
+ }
297
+
298
+ /**
299
+ * Creates a new ImageSource from the given image, using the given sizing options.
300
+ * @param image The image asset that should be put into an ImageSource.
301
+ * @param options The options that should be used to create the ImageSource.
302
+ */
303
+ createPHImage ( image : PHAsset , options ?: ImageOptions ) : Promise < image_source . ImageSource > {
304
+ return new Promise < image_source . ImageSource > ( ( resolve , reject ) => {
305
+ var size : CGSize = options ? CGSizeMake ( options . maxWidth , options . maxHeight ) : PHImageManagerMaximumSize ;
306
+ var resizeMode = PHImageRequestOptions . alloc ( ) . init ( ) ;
307
+
308
+ // TODO: Decide whether it is benefical to use PHImageRequestOptionsResizeModeFast
309
+ // Accuracy vs Performance. It is probably best to expose these as iOS specific options.
310
+ resizeMode . resizeMode = PHImageRequestOptionsResizeMode . PHImageRequestOptionsResizeModeExact ;
311
+ resizeMode . synchronous = false ;
312
+
313
+ // TODO: provide the ability to change this setting.
314
+ // Right now, it is needed to make sure that resolve is not called twice.
315
+ resizeMode . deliveryMode = PHImageRequestOptionsDeliveryMode . PHImageRequestOptionsDeliveryModeHighQualityFormat ;
316
+ resizeMode . normalizedCropRect = CGRectMake ( 0 , 0 , 1 , 1 ) ;
317
+ PHImageManager . defaultManager ( ) . requestImageForAssetTargetSizeContentModeOptionsResultHandler (
318
+ image ,
319
+ size ,
320
+ PHImageContentMode . PHImageContentModeAspectFill ,
321
+ resizeMode ,
322
+ ( createdImage , data ) => {
323
+ if ( createdImage ) {
324
+ var imageSource = new image_source . ImageSource ( ) ;
325
+ imageSource . setNativeSource ( createdImage ) ;
326
+
327
+ // TODO: Determine whether runOnRunLoop is needed
328
+ // for callback or not. (See the data() implementation in AssetPH below)
329
+ resolve ( imageSource ) ;
330
+ } else {
331
+ reject ( new Error ( "The image could not be created." ) ) ;
332
+ }
333
+ }
334
+ ) ;
335
+ } ) ;
307
336
}
308
337
309
338
done ( ) : void {
@@ -376,6 +405,16 @@ class AssetPH extends Asset {
376
405
return this . _phAsset . localIdentifier . toString ( ) ;
377
406
}
378
407
408
+ getImage ( options ?: ImageOptions ) : Promise < image_source . ImageSource > {
409
+ return ( < ImagePickerPH > ( < AlbumPH > this . album ) . imagePicker ) . createPHImage ( this . _phAsset , options ) ;
410
+ }
411
+
412
+ getImageData ( ) : Promise < ArrayBuffer > {
413
+ return this . data ( ) . then ( ( data : NSData ) => {
414
+ return ( < any > interop ) . bufferFromData ( data ) ;
415
+ } ) ;
416
+ }
417
+
379
418
get fileUri ( ) : string {
380
419
if ( ! AssetPH . _uriRequestOptions ) {
381
420
AssetPH . _uriRequestOptions = PHImageRequestOptions . alloc ( ) . init ( ) ;
@@ -392,7 +431,7 @@ class AssetPH extends Asset {
392
431
return undefined ;
393
432
}
394
433
395
- data ( ) : Thenable < any > {
434
+ data ( ) : Promise < any > {
396
435
return new Promise ( ( resolve , reject ) => {
397
436
var runloop = CFRunLoopGetCurrent ( ) ;
398
437
PHImageManager . defaultManager ( ) . requestImageDataForAssetOptionsResultHandler ( this . _phAsset , null , ( data , dataUTI , orientation , info ) => {
0 commit comments