Files
NativeScript/Image/image.ios.ts
hshristov ca201cf9d7 Fixed iOS BCL to use properties instead of methods.
Fixed web_client to call .toString() on NSString
Fixed BCL project to use version 1.0
2014-04-07 13:48:36 +03:00

60 lines
1.5 KiB
TypeScript

export enum ImageType {
PNG = 0,
JPEG = 1,
}
export class Image {
public ios: any;
constructor() {
this.ios = null;
}
public loadFromResource(name: string): boolean {
this.ios = UIKit.UIImage.imageNamed(name);
return (this.ios != null);
}
public loadFromFile(path: string): boolean {
this.ios = UIKit.UIImage.imageWithContentsOfFile(path);
return (this.ios != null);
}
public loadFromData(data: any): boolean {
this.ios = UIKit.UIImage.imageWithData(data);
return (this.ios != null);
}
public loadFromBitmap(source: any): boolean {
this.ios = source;
return (this.ios != null);
}
public saveToFile(path: string, format: ImageType, quality?: number): boolean {
if (null == this.ios) {
return false;
}
var res = false;
var data = null;
switch (format) {
case ImageType.JPEG:
data = UIKit.UIImageJPEGRepresentation(this.ios, ('undefined' == typeof quality) ? 1.0 : quality);
break;
case ImageType.PNG:
data = UIKit.UIImagePNGRepresentation(this.ios);
break;
}
if (null != data) {
res = data.writeToFileAtomically(path, true);
}
return res;
}
public getHeight(): number {
return (this.ios) ? this.ios.size.height : NaN;
}
public getWidth(): number {
return (this.ios) ? this.ios.size.width : NaN;
}
}