-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnativescript-image-colors.ios.ts
38 lines (31 loc) · 1.51 KB
/
nativescript-image-colors.ios.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { ColorPalette, IosPalette } from './nativescript-image-colors.common';
import { Image } from 'tns-core-modules/ui/image';
import { Color } from 'tns-core-modules/color';
declare const SLColorArt: any;
export class ImageColors {
public static getColorPalette(image: Image): ColorPalette {
let returnPalette: ColorPalette = {
color1: new Color('black'),
color2: new Color('black'),
color3: new Color('black'),
AndroidPalette: null,
IosPalette: <any>{}
};
let colors = SLColorArt.alloc().initWithImage(image.ios.image);
returnPalette.color1 = this.UIDeviceRGBColoSpace(colors.backgroundColor.toString());
returnPalette.color2 = this.UIDeviceRGBColoSpace(colors.primaryColor.toString());
returnPalette.color3 = this.UIDeviceRGBColoSpace(colors.secondaryColor.toString());
returnPalette.IosPalette = <IosPalette>{
backgroundColor: this.UIDeviceRGBColoSpace(colors.backgroundColor.toString()),
primaryColor: this.UIDeviceRGBColoSpace(colors.primaryColor.toString()),
secondaryColor: this.UIDeviceRGBColoSpace(colors.secondaryColor.toString()),
detailColor: this.UIDeviceRGBColoSpace(colors.detailColor.toString())
}
return returnPalette;
}
private static UIDeviceRGBColoSpace(uicolor: any): Color {
let rgbStrings: string[] = (<string>uicolor).replace('UIDeviceRGBColorSpace ', '').split(' ');
let rgbNumbers: number[] = <any>rgbStrings.filter(value => !isNaN(<any>value)).map(value => parseFloat(value) * 255);
return new Color(rgbNumbers[0], rgbNumbers[1], rgbNumbers[2], 1);
}
}