mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
async load of images in web client + loadFromBitmap for Image
This commit is contained in:
@@ -37,6 +37,11 @@ export module tk {
|
||||
return (this._nativeImage != null);
|
||||
}
|
||||
|
||||
public loadFromBitmap(source: any): boolean {
|
||||
this._nativeImage = source;
|
||||
return (this._nativeImage != null);
|
||||
}
|
||||
|
||||
public saveToFile(path: string, format: ImageType, quality?: number): boolean {
|
||||
if (this._nativeImage) {
|
||||
var targetFormat = android.graphics.Bitmap.CompressFormat.PNG;
|
||||
|
||||
1
Image/image.d.ts
vendored
1
Image/image.d.ts
vendored
@@ -9,6 +9,7 @@
|
||||
loadFromResource(name: string): boolean;
|
||||
loadFromFile(path: string): boolean;
|
||||
loadFromData(data: any): boolean;
|
||||
loadFromBitmap(source: any): boolean;
|
||||
saveToFile(path: string, format: ImageType, quality?: number): boolean;
|
||||
|
||||
getHeight(): number;
|
||||
|
||||
@@ -27,6 +27,11 @@
|
||||
return (this._nativeImage != null);
|
||||
}
|
||||
|
||||
public loadFromBitmap(source: any): boolean {
|
||||
this._nativeImage = source;
|
||||
return (this._nativeImage != null);
|
||||
}
|
||||
|
||||
public saveToFile(path: string, format: ImageType, quality?: number): boolean {
|
||||
if (null == this._nativeImage) {
|
||||
return false;
|
||||
|
||||
@@ -20,7 +20,6 @@ export module tk {
|
||||
errorCallback(e.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
successCallback(result);
|
||||
}
|
||||
})).get();
|
||||
@@ -45,9 +44,20 @@ export module tk {
|
||||
public getImage(url: string, successCallback: (result: image_module.tk.ui.Image) => void, errorCallback?: (e: Error) => void) {
|
||||
try {
|
||||
if (successCallback) {
|
||||
var image = new image_module.tk.ui.Image();
|
||||
image.loadFromData(new java.net.URL(url).getContent());
|
||||
successCallback(image);
|
||||
var context = app_module.tk.ui.Application.current.android.context;
|
||||
com.koushikdutta.ion.Ion.with(context, url).asBitmap().setCallback(new com.koushikdutta.async.future.FutureCallback({
|
||||
onCompleted: function (e, result) {
|
||||
if (e && errorCallback) {
|
||||
errorCallback(e.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
var image = new image_module.tk.ui.Image();
|
||||
image.loadFromBitmap(result);
|
||||
|
||||
successCallback(image);
|
||||
}
|
||||
})).get();
|
||||
}
|
||||
} catch (ex) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user