(callback: (image, error) => void)
| 32 | } |
| 33 | |
| 34 | public getImageAsync(callback: (image, error) => void) { |
| 35 | if (!this.ios && !this.nativeImage) { |
| 36 | callback(null, 'Asset cannot be found.'); |
| 37 | } |
| 38 | |
| 39 | const srcWidth = this.nativeImage ? this.nativeImage.size.width : this.ios.pixelWidth; |
| 40 | const srcHeight = this.nativeImage ? this.nativeImage.size.height : this.ios.pixelHeight; |
| 41 | const requestedSize = getRequestedImageSize({ width: srcWidth, height: srcHeight }, this.options); |
| 42 | |
| 43 | if (this.nativeImage) { |
| 44 | callback(this.scaleImage(this.nativeImage, CGSizeMake(requestedSize.width, requestedSize.height)), null); |
| 45 | queueGC(); |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | const imageRequestOptions = PHImageRequestOptions.alloc().init(); |
| 50 | imageRequestOptions.deliveryMode = PHImageRequestOptionsDeliveryMode.HighQualityFormat; |
| 51 | imageRequestOptions.networkAccessAllowed = true; |
| 52 | |
| 53 | PHImageManager.defaultManager().requestImageForAssetTargetSizeContentModeOptionsResultHandler(this.ios, requestedSize, PHImageContentMode.AspectFit, imageRequestOptions, (image, imageResultInfo) => { |
| 54 | if (image) { |
| 55 | callback(this.scaleImage(image, requestedSize), null); |
| 56 | } else { |
| 57 | callback(null, imageResultInfo.valueForKey(PHImageErrorKey)); |
| 58 | } |
| 59 | queueGC(); |
| 60 | }); |
| 61 | } |
| 62 | |
| 63 | private scaleImage(image: UIImage, requestedSize: { width: number; height: number }): UIImage { |
| 64 | return NativeScriptUtils.scaleImageWidthHeightScaleFactor(image, requestedSize.width, requestedSize.height, this.options?.autoScaleFactor === false ? 1.0 : 0.0); |
no test coverage detected