import { TNSImageAssetBase , TNSImageAssetSaveFormat , } from './canvas-plugin.common' ; import * as fs from '@nativescript/core/file-system' ; export class TNSImageAsset extends TNSImageAssetBase { constructor ( ) { super ( new com . github . triniwiz . canvas . ImageAsset ( ) ) ; } get width ( ) { return this . native . getWidth ( ) ; } get height ( ) { return this . native . getHeight ( ) ; } get error ( ) : string { return this . native . getError ( ) ; } static toPrimitive ( value ) { if ( value instanceof java . lang . Integer ) { return value . intValue ( ) ; } else if ( value instanceof java . lang . Long ) { return value . longValue ( ) ; } else if ( value instanceof java . lang . Short ) { return value . shortValue ( ) ; } else if ( value instanceof java . lang . Byte ) { return value . byteValue ( ) ; } else if ( value instanceof java . lang . Boolean ) { return value . booleanValue ( ) ; } else if ( value instanceof java . lang . String ) { return value . toString ( ) ; } else if ( value instanceof java . lang . Float ) { return value . floatValue ( ) ; } else if ( value instanceof java . lang . Double ) { return value . doubleValue ( ) ; } return value ; } loadFile ( path ) { let realPath = path ; if ( typeof realPath === 'string' ) { if ( realPath . startsWith ( '~/' ) ) { realPath = fs . path . join ( fs . knownFolders . currentApp ( ) . path , realPath . replace ( '~/' , '' ) ) ; } } return this . native . loadImageFromPath ( realPath ) ; } loadFileAsync ( path ) { return new Promise ( ( resolve , reject ) => { if ( typeof path === 'string' ) { if ( path . startsWith ( '~/' ) ) { path = fs . path . join ( fs . knownFolders . currentApp ( ) . path , path . replace ( '~/' , '' ) ) ; } } this . native . loadImageFromPathAsync ( path , new com . github . triniwiz . canvas . ImageAsset . Callback ( { onError ( error ) { reject ( error ) ; } , onSuccess ( success ) { resolve ( TNSImageAsset . toPrimitive ( success ) ) ; } , } ) ) ; } ) ; } loadFromNative ( image ) { return this . native . loadImageFromImage ( image ) ; } loadFromNativeAsync ( image ) { return new Promise ( ( resolve , reject ) => { this . native . loadImageFromImageAsync ( image , new com . github . triniwiz . canvas . ImageAsset . Callback ( { onError ( error ) { reject ( error ) ; } , onSuccess ( success ) { resolve ( TNSImageAsset . toPrimitive ( success ) ) ; } , } ) ) ; } ) ; } loadFromBytes ( bytes ) { if ( bytes instanceof Uint8Array || bytes instanceof Uint8ClampedArray ) { let buf = java . nio . ByteBuffer . wrap ( Array . from ( bytes ) ) ; return this . native . loadImageFromBytes ( buf . array ( ) ) ; } return this . native . loadImageFromBytes ( bytes as any ) ; } loadFromBytesAsync ( bytes ) { return new Promise ( ( resolve , reject ) => { const callback = new com . github . triniwiz . canvas . ImageAsset . Callback ( { onError ( error ) { reject ( error ) ; } , onSuccess ( success ) { resolve ( TNSImageAsset . toPrimitive ( success ) ) ; } , } ) ; if ( bytes instanceof Uint8Array || bytes instanceof Uint8ClampedArray ) { let buf = java . nio . ByteBuffer . wrap ( Array . from ( bytes ) ) ; this . native . loadImageFromBytesAsync ( buf . array ( ) , callback ) ; } else { this . native . loadImageFromBytesAsync ( bytes as any , callback ) ; } } ) ; } scale ( x , y ) { this . native . scale ( x , y ) ; } save ( path , format ) { let realFormat ; switch ( format ) { case TNSImageAssetSaveFormat . PNG : realFormat = com . github . triniwiz . canvas . ImageAssetFormat . PNG ; break ; case TNSImageAssetSaveFormat . ICO : realFormat = com . github . triniwiz . canvas . ImageAssetFormat . ICO ; break ; case TNSImageAssetSaveFormat . BMP : realFormat = com . github . triniwiz . canvas . ImageAssetFormat . BMP ; break ; case TNSImageAssetSaveFormat . TIFF : realFormat = com . github . triniwiz . canvas . ImageAssetFormat . TIFF ; break ; default : realFormat = com . github . triniwiz . canvas . ImageAssetFormat . JPG ; break ; } return this . native . save ( path , realFormat ) ; } saveAsync ( path , format ) { return new Promise ( ( resolve , reject ) => { let realFormat ; switch ( format ) { case TNSImageAssetSaveFormat . PNG : realFormat = com . github . triniwiz . canvas . ImageAssetFormat . PNG ; break ; case TNSImageAssetSaveFormat . ICO : realFormat = com . github . triniwiz . canvas . ImageAssetFormat . ICO ; break ; case TNSImageAssetSaveFormat . BMP : realFormat = com . github . triniwiz . canvas . ImageAssetFormat . BMP ; break ; case TNSImageAssetSaveFormat . TIFF : realFormat = com . github . triniwiz . canvas . ImageAssetFormat . TIFF ; break ; default : realFormat = com . github . triniwiz . canvas . ImageAssetFormat . JPG ; break ; } ( this . native as com . github . triniwiz . canvas . ImageAsset ) . saveAsync ( path , realFormat , new com . github . triniwiz . canvas . ImageAsset . Callback ( { onError ( error ) { reject ( error ) ; } , onSuccess ( success ) { resolve ( TNSImageAsset . toPrimitive ( success ) ) ; } , } ) ) ; } ) ; } flipX ( ) { this . native . flipX ( ) ; } flipY ( ) { this . native . flipY ( ) ; } } declare namespace com { export namespace github { export namespace triniwiz { export namespace canvas { export class ImageAsset { public static class : java . lang . Class < com . github . triniwiz . canvas . ImageAsset > ; public constructor ( ) ; public loadImageFromPathAsync ( param0 , param1 ) ; public flipX ( ) ; public getHeight ( ) ; public finalize ( ) ; public getWidth ( ) ; public loadImageFromPath ( param0 ) ; public loadImageFromImage ( param0 ) ; public save ( param0 , param1 ) ; public getBytes ( ) ; public getError ( ) ; public loadImageFromImageAsync ( param0 , param1 ) ; public flipY ( ) ; public scale ( param0 , param1 ) ; public loadImageFromBytesAsync ( param0 , param1 ) ; public saveAsync ( param0 , param1 , param2 ) ; public loadImageFromBytes ( param0 ) ; } export namespace ImageAsset { export class Callback { public static class : java . lang . Class < com . github . triniwiz . canvas . ImageAsset . Callback > ; /**
                         * Constructs a new instance of the com.github.triniwiz.canvas.ImageAsset$Callback interface with the provided implementation. An empty constructor exists calling super() when extending the interface class.
                         */ public constructor ( implementation ) ; public constructor ( ) ; public onSuccess ( param0 ) ; public onError ( param0 ) ; } } } } } } declare namespace com { export namespace github { export namespace triniwiz { export namespace canvas { export class ImageAssetFormat { public static class : java . lang . Class < com . github . triniwiz . canvas . ImageAssetFormat > ; public static JPG : com . github . triniwiz . canvas . ImageAssetFormat ; public static PNG : com . github . triniwiz . canvas . ImageAssetFormat ; public static ICO : com . github . triniwiz . canvas . ImageAssetFormat ; public static BMP : com . github . triniwiz . canvas . ImageAssetFormat ; public static TIFF : com . github . triniwiz . canvas . ImageAssetFormat ; public static valueOf ( param0 ) ; public static values ( ) ; public getFormat ( ) ; } } } } }