MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / getImageAsync

Method getImageAsync

packages/core/image-asset/index.ios.ts:34–61  ·  view source on GitHub ↗
(callback: (image, error) => void)

Source from the content-addressed store, hash-verified

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);

Callers 2

fromAssetMethod · 0.45
fromAssetMethod · 0.45

Calls 5

scaleImageMethod · 0.95
getRequestedImageSizeFunction · 0.90
queueGCFunction · 0.90
callbackFunction · 0.50
initMethod · 0.45

Tested by

no test coverage detected