| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -111,20 +111,37 @@ export function testFromAssetSimple(done) { | |||
| 111 | 111 | }); | |
| 112 | 112 | } | |
| 113 | 113 | ||
| 114 | - export function testFromAssetWithScaling(done) { | ||
| 114 | + export function testFromAssetWithExactScaling(done) { | ||
| 115 | 115 | let asset = new imageAssetModule.ImageAsset(splashscreenPath); | |
| 116 | 116 | let scaleWidth = 10; | |
| 117 | 117 | let scaleHeight = 11; | |
| 118 | 118 | asset.options = { | |
| 119 | 119 | width: scaleWidth, | |
| 120 | 120 | height: scaleHeight, | |
| 121 | - keepAspectRatio: false | ||
| 121 | + keepAspectRatio: false, | ||
| 122 | + autoScaleFactor: false | ||
| 122 | 123 | }; | |
| 123 | 124 | ||
| 124 | - let img = imageSource.fromAsset(asset).then((source) => { | ||
| 125 | + imageSource.fromAsset(asset).then((source) => { | ||
| 125 | 126 | TKUnit.assertEqual(source.width, scaleWidth); | |
| 126 | 127 | TKUnit.assertEqual(source.height, scaleHeight); | |
| 127 | - done(); | ||
| 128 | + | ||
| 129 | + const targetFilename = `splashscreenTemp.png`; | ||
| 130 | + const tempPath = fs.knownFolders.temp().path; | ||
| 131 | + const localFullPath = fs.path.join(tempPath, targetFilename); | ||
| 132 | + | ||
| 133 | + const fullImageSaved = source.saveToFile(localFullPath, "png"); | ||
| 134 | + | ||
| 135 | + if (fullImageSaved) { | ||
| 136 | + let sourceImage = new imageSource.ImageSource(); | ||
| 137 | + sourceImage.fromFile(localFullPath).then(() => { | ||
| 138 | + TKUnit.assertEqual(sourceImage.width, scaleWidth); | ||
| 139 | + TKUnit.assertEqual(sourceImage.height, scaleHeight); | ||
| 140 | + done(); | ||
| 141 | + }); | ||
| 142 | + } else { | ||
| 143 | + done(`Error saving photo to local temp folder: ${localFullPath}`); | ||
| 144 | + } | ||
| 128 | 145 | }, (error) => { | |
| 129 | 146 | done(error); | |
| 130 | 147 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,16 +2,16 @@ import * as definition from "."; | |||
| 2 | 2 | import * as observable from "../data/observable"; | |
| 3 | 3 | import * as platform from "../platform"; | |
| 4 | 4 | ||
| 5 | - export class ImageAsset extends observable.Observable implements definition.ImageAsset { | ||
| 5 | + export class ImageAsset extends observable.Observable implements definition.ImageAsset { | ||
| 6 | 6 | private _options: definition.ImageAssetOptions; | |
| 7 | 7 | private _nativeImage: any; | |
| 8 | 8 | ||
| 9 | 9 | ios: PHAsset; | |
| 10 | 10 | android: string; | |
| 11 | 11 | ||
| 12 | - constructor () { | ||
| 12 | + constructor() { | ||
| 13 | 13 | super(); | |
| 14 | - this._options = { keepAspectRatio: true }; | ||
| 14 | + this._options = { keepAspectRatio: true, autoScaleFactor: true }; | ||
| 15 | 15 | } | |
| 16 | 16 | ||
| 17 | 17 | get options(): definition.ImageAssetOptions { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,4 +17,5 @@ export interface ImageAssetOptions { | |||
| 17 | 17 | width?: number; | |
| 18 | 18 | height?: number; | |
| 19 | 19 | keepAspectRatio?: boolean; | |
| 20 | + autoScaleFactor?: boolean; | ||
| 20 | 21 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,7 +50,7 @@ export class ImageAsset extends common.ImageAsset { | |||
| 50 | 50 | let imageRequestOptions = PHImageRequestOptions.alloc().init(); | |
| 51 | 51 | imageRequestOptions.deliveryMode = PHImageRequestOptionsDeliveryMode.HighQualityFormat; | |
| 52 | 52 | imageRequestOptions.networkAccessAllowed = true; | |
| 53 | - | ||
| 53 | + | ||
| 54 | 54 | PHImageManager.defaultManager().requestImageForAssetTargetSizeContentModeOptionsResultHandler(this.ios, requestedSize, PHImageContentMode.AspectFit, imageRequestOptions, | |
| 55 | 55 | (image, imageResultInfo) => { | |
| 56 | 56 | if (image) { | |
@@ -64,8 +64,11 @@ export class ImageAsset extends common.ImageAsset { | |||
| 64 | 64 | ); | |
| 65 | 65 | } | |
| 66 | 66 | ||
| 67 | - private scaleImage(image: UIImage, requestedSize: {width: number, height: number}): UIImage { | ||
| 68 | - UIGraphicsBeginImageContextWithOptions(requestedSize, false, 0.0); | ||
| 67 | + private scaleImage(image: UIImage, requestedSize: { width: number, height: number }): UIImage { | ||
| 68 | + // scaleFactor = 0 takes the scale factor of the devices's main screen. | ||
| 69 | + const scaleFactor = this.options && this.options.autoScaleFactor === false ? 1.0 : 0.0; | ||
| 70 | + | ||
| 71 | + UIGraphicsBeginImageContextWithOptions(requestedSize, false, scaleFactor); | ||
| 69 | 72 | image.drawInRect(CGRectMake(0, 0, requestedSize.width, requestedSize.height)); | |
| 70 | 73 | let resultImage = UIGraphicsGetImageFromCurrentImageContext(); | |
| 71 | 74 | UIGraphicsEndImageContext(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -190,7 +190,7 @@ function getFileName(path: string): string { | |||
| 190 | 190 | return fileName; | |
| 191 | 191 | } | |
| 192 | 192 | ||
| 193 | - function getImageData(instance: UIImage, format: "png" | "jpeg" | "jpg", quality = 1.0): NSData { | ||
| 193 | + function getImageData(instance: UIImage, format: "png" | "jpeg" | "jpg", quality = 0.9): NSData { | ||
| 194 | 194 | var data = null; | |
| 195 | 195 | switch (format) { | |
| 196 | 196 | case "png": | |
| Back | FazBrowse Home | New Git URL |
0 commit comments