mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat(ImageSource): resize method (#8678)
This commit is contained in:
@@ -10,6 +10,8 @@ import { getNativeApplication } from "../application";
|
||||
import { Font } from "../ui/styling/font";
|
||||
import { Color } from "../color";
|
||||
|
||||
import { getScaledDimensions } from "./image-source-common";
|
||||
|
||||
export { isFileOrResourcePath };
|
||||
|
||||
let http: typeof httpModule;
|
||||
@@ -337,6 +339,18 @@ export class ImageSource implements ImageSourceDefinition {
|
||||
|
||||
return outputStream.toString();
|
||||
}
|
||||
|
||||
public resize(maxSize: number, options?: any): ImageSource {
|
||||
const dim = getScaledDimensions(this.android.getWidth(), this.android.getHeight(), maxSize);
|
||||
const bm: android.graphics.Bitmap = android.graphics.Bitmap.createScaledBitmap(
|
||||
this.android,
|
||||
dim.width,
|
||||
dim.height,
|
||||
options && options.filter
|
||||
);
|
||||
|
||||
return new ImageSource(bm);
|
||||
}
|
||||
}
|
||||
|
||||
function getTargetFormat(format: "png" | "jpeg" | "jpg"): android.graphics.Bitmap.CompressFormat {
|
||||
|
||||
Reference in New Issue
Block a user