mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-18 13:51:27 +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 {
|
export class Image {
|
||||||
private _nativeImage: any;
|
public android: any;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._nativeImage = null;
|
this.android = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public loadFromResource(name: string): boolean {
|
public loadFromResource(name: string): boolean {
|
||||||
@ -20,30 +20,30 @@ export module tk {
|
|||||||
if (res) {
|
if (res) {
|
||||||
var identifier: number = res.getIdentifier(name, 'drawable', androidApp.packageName);
|
var identifier: number = res.getIdentifier(name, 'drawable', androidApp.packageName);
|
||||||
if (0 < identifier) {
|
if (0 < identifier) {
|
||||||
this._nativeImage = android.graphics.BitmapFactory.decodeResource(res, identifier);
|
this.android = android.graphics.BitmapFactory.decodeResource(res, identifier);
|
||||||
return (this._nativeImage != null);
|
return (this.android != null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public loadFromFile(path: string): boolean {
|
public loadFromFile(path: string): boolean {
|
||||||
this._nativeImage = android.graphics.BitmapFactory.decodeFile(path, null);
|
this.android = android.graphics.BitmapFactory.decodeFile(path, null);
|
||||||
return (this._nativeImage != null);
|
return (this.android != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public loadFromData(data: any): boolean {
|
public loadFromData(data: any): boolean {
|
||||||
this._nativeImage = android.graphics.BitmapFactory.decodeStream(data);
|
this.android = android.graphics.BitmapFactory.decodeStream(data);
|
||||||
return (this._nativeImage != null);
|
return (this.android != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public loadFromBitmap(source: any): boolean {
|
public loadFromBitmap(source: any): boolean {
|
||||||
this._nativeImage = source;
|
this.android = source;
|
||||||
return (this._nativeImage != null);
|
return (this.android != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public saveToFile(path: string, format: ImageType, quality?: number): boolean {
|
public saveToFile(path: string, format: ImageType, quality?: number): boolean {
|
||||||
if (this._nativeImage) {
|
if (this.android) {
|
||||||
var targetFormat = android.graphics.Bitmap.CompressFormat.PNG;
|
var targetFormat = android.graphics.Bitmap.CompressFormat.PNG;
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case ImageType.JPEG:
|
case ImageType.JPEG:
|
||||||
@ -54,7 +54,7 @@ export module tk {
|
|||||||
// TODO add exception handling
|
// TODO add exception handling
|
||||||
var outputStream = new java.io.BufferedOutputStream(new java.io.FileOutputStream(path));
|
var outputStream = new java.io.BufferedOutputStream(new java.io.FileOutputStream(path));
|
||||||
// FIXME compress is not found
|
// FIXME compress is not found
|
||||||
var res = this._nativeImage.compress(targetFormat, outputStream);
|
var res = this.android.compress(targetFormat, outputStream);
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -62,11 +62,11 @@ export module tk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getHeight(): number {
|
public getHeight(): number {
|
||||||
return (this._nativeImage) ? this._nativeImage.getHeight() : NaN;
|
return (this.android) ? this.android.getHeight() : NaN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getWidth(): number {
|
public getWidth(): number {
|
||||||
return (this._nativeImage) ? this._nativeImage.getWidth() : NaN;
|
return (this.android) ? this.android.getWidth() : NaN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,44 +6,44 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Image {
|
export class Image {
|
||||||
private _nativeImage: any;
|
public ios: any;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._nativeImage = null;
|
this.ios = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public loadFromResource(name: string): boolean {
|
public loadFromResource(name: string): boolean {
|
||||||
this._nativeImage = UIKit.UIImage.imageNamed(name);
|
this.ios = UIKit.UIImage.imageNamed(name);
|
||||||
return (this._nativeImage != null);
|
return (this.ios != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public loadFromFile(path: string): boolean {
|
public loadFromFile(path: string): boolean {
|
||||||
this._nativeImage = UIKit.UIImage.imageWithContentsOfFile(path);
|
this.ios = UIKit.UIImage.imageWithContentsOfFile(path);
|
||||||
return (this._nativeImage != null);
|
return (this.ios != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public loadFromData(data: any): boolean {
|
public loadFromData(data: any): boolean {
|
||||||
this._nativeImage = UIKit.UIImage.imageWithData(data);
|
this.ios = UIKit.UIImage.imageWithData(data);
|
||||||
return (this._nativeImage != null);
|
return (this.ios != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public loadFromBitmap(source: any): boolean {
|
public loadFromBitmap(source: any): boolean {
|
||||||
this._nativeImage = source;
|
this.ios = source;
|
||||||
return (this._nativeImage != null);
|
return (this.ios != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public saveToFile(path: string, format: ImageType, quality?: number): boolean {
|
public saveToFile(path: string, format: ImageType, quality?: number): boolean {
|
||||||
if (null == this._nativeImage) {
|
if (null == this.ios) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var res = false;
|
var res = false;
|
||||||
var data = null;
|
var data = null;
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case ImageType.JPEG:
|
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;
|
break;
|
||||||
case ImageType.PNG:
|
case ImageType.PNG:
|
||||||
data = UIKit.UIImagePNGRepresentation(this._nativeImage);
|
data = UIKit.UIImagePNGRepresentation(this.ios);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (null != data) {
|
if (null != data) {
|
||||||
@ -53,11 +53,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getHeight(): number {
|
public getHeight(): number {
|
||||||
return (this._nativeImage) ? this._nativeImage.size().height : NaN;
|
return (this.ios) ? this.ios.size().height : NaN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getWidth(): number {
|
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