mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-18 05:18:39 +08:00
_nativeImage change to ios and android and now is public
This commit is contained in:
@ -8,10 +8,10 @@ export module tk {
|
||||
}
|
||||
|
||||
export class Image {
|
||||
private _nativeImage: any;
|
||||
public android: any;
|
||||
|
||||
constructor() {
|
||||
this._nativeImage = null;
|
||||
this.android = null;
|
||||
}
|
||||
|
||||
public loadFromResource(name: string): boolean {
|
||||
@ -20,30 +20,30 @@ export module tk {
|
||||
if (res) {
|
||||
var identifier: number = res.getIdentifier(name, 'drawable', androidApp.packageName);
|
||||
if (0 < identifier) {
|
||||
this._nativeImage = android.graphics.BitmapFactory.decodeResource(res, identifier);
|
||||
return (this._nativeImage != null);
|
||||
this.android = android.graphics.BitmapFactory.decodeResource(res, identifier);
|
||||
return (this.android != null);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public loadFromFile(path: string): boolean {
|
||||
this._nativeImage = android.graphics.BitmapFactory.decodeFile(path, null);
|
||||
return (this._nativeImage != null);
|
||||
this.android = android.graphics.BitmapFactory.decodeFile(path, null);
|
||||
return (this.android != null);
|
||||
}
|
||||
|
||||
public loadFromData(data: any): boolean {
|
||||
this._nativeImage = android.graphics.BitmapFactory.decodeStream(data);
|
||||
return (this._nativeImage != null);
|
||||
this.android = android.graphics.BitmapFactory.decodeStream(data);
|
||||
return (this.android != null);
|
||||
}
|
||||
|
||||
public loadFromBitmap(source: any): boolean {
|
||||
this._nativeImage = source;
|
||||
return (this._nativeImage != null);
|
||||
this.android = source;
|
||||
return (this.android != null);
|
||||
}
|
||||
|
||||
public saveToFile(path: string, format: ImageType, quality?: number): boolean {
|
||||
if (this._nativeImage) {
|
||||
if (this.android) {
|
||||
var targetFormat = android.graphics.Bitmap.CompressFormat.PNG;
|
||||
switch (format) {
|
||||
case ImageType.JPEG:
|
||||
@ -54,7 +54,7 @@ export module tk {
|
||||
// TODO add exception handling
|
||||
var outputStream = new java.io.BufferedOutputStream(new java.io.FileOutputStream(path));
|
||||
// FIXME compress is not found
|
||||
var res = this._nativeImage.compress(targetFormat, outputStream);
|
||||
var res = this.android.compress(targetFormat, outputStream);
|
||||
outputStream.close();
|
||||
return res;
|
||||
}
|
||||
@ -62,11 +62,11 @@ export module tk {
|
||||
}
|
||||
|
||||
public getHeight(): number {
|
||||
return (this._nativeImage) ? this._nativeImage.getHeight() : NaN;
|
||||
return (this.android) ? this.android.getHeight() : NaN;
|
||||
}
|
||||
|
||||
public getWidth(): number {
|
||||
return (this._nativeImage) ? this._nativeImage.getWidth() : NaN;
|
||||
return (this.android) ? this.android.getWidth() : NaN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,44 +6,44 @@
|
||||
}
|
||||
|
||||
export class Image {
|
||||
private _nativeImage: any;
|
||||
public ios: any;
|
||||
|
||||
constructor() {
|
||||
this._nativeImage = null;
|
||||
this.ios = null;
|
||||
}
|
||||
|
||||
public loadFromResource(name: string): boolean {
|
||||
this._nativeImage = UIKit.UIImage.imageNamed(name);
|
||||
return (this._nativeImage != null);
|
||||
this.ios = UIKit.UIImage.imageNamed(name);
|
||||
return (this.ios != null);
|
||||
}
|
||||
|
||||
public loadFromFile(path: string): boolean {
|
||||
this._nativeImage = UIKit.UIImage.imageWithContentsOfFile(path);
|
||||
return (this._nativeImage != null);
|
||||
this.ios = UIKit.UIImage.imageWithContentsOfFile(path);
|
||||
return (this.ios != null);
|
||||
}
|
||||
|
||||
public loadFromData(data: any): boolean {
|
||||
this._nativeImage = UIKit.UIImage.imageWithData(data);
|
||||
return (this._nativeImage != null);
|
||||
this.ios = UIKit.UIImage.imageWithData(data);
|
||||
return (this.ios != null);
|
||||
}
|
||||
|
||||
public loadFromBitmap(source: any): boolean {
|
||||
this._nativeImage = source;
|
||||
return (this._nativeImage != null);
|
||||
this.ios = source;
|
||||
return (this.ios != null);
|
||||
}
|
||||
|
||||
public saveToFile(path: string, format: ImageType, quality?: number): boolean {
|
||||
if (null == this._nativeImage) {
|
||||
if (null == this.ios) {
|
||||
return false;
|
||||
}
|
||||
var res = false;
|
||||
var data = null;
|
||||
switch (format) {
|
||||
case ImageType.JPEG:
|
||||
data = UIKit.UIImageJPEGRepresentation(this._nativeImage, ('undefined' == typeof quality) ? 1.0 : quality);
|
||||
data = UIKit.UIImageJPEGRepresentation(this.ios, ('undefined' == typeof quality) ? 1.0 : quality);
|
||||
break;
|
||||
case ImageType.PNG:
|
||||
data = UIKit.UIImagePNGRepresentation(this._nativeImage);
|
||||
data = UIKit.UIImagePNGRepresentation(this.ios);
|
||||
break;
|
||||
}
|
||||
if (null != data) {
|
||||
@ -53,11 +53,11 @@
|
||||
}
|
||||
|
||||
public getHeight(): number {
|
||||
return (this._nativeImage) ? this._nativeImage.size().height : NaN;
|
||||
return (this.ios) ? this.ios.size().height : NaN;
|
||||
}
|
||||
|
||||
public getWidth(): number {
|
||||
return (this._nativeImage) ? this._nativeImage.size().width : NaN;
|
||||
return (this.ios) ? this.ios.size().width : NaN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user