mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
feat(ImageSource): resize method (#8678)
This commit is contained in:
@ -9,6 +9,8 @@ import { Color } from "../color";
|
||||
import { path as fsPath, knownFolders } from "../file-system";
|
||||
import { isFileOrResourcePath, RESOURCE_PREFIX, layout } from "../utils/utils";
|
||||
|
||||
import { getScaledDimensions } from "./image-source-common";
|
||||
|
||||
export { isFileOrResourcePath };
|
||||
|
||||
let http: typeof httpModule;
|
||||
@ -336,6 +338,24 @@ export class ImageSource implements ImageSourceDefinition {
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
public resize(maxSize: number, options?: any): ImageSource {
|
||||
const size: CGSize = this.ios.size;
|
||||
const dim = getScaledDimensions(
|
||||
size.width,
|
||||
size.height,
|
||||
maxSize
|
||||
);
|
||||
|
||||
const newSize: CGSize = CGSizeMake(dim.width, dim.height);
|
||||
UIGraphicsBeginImageContextWithOptions(newSize, true, this.ios.scale);
|
||||
this.ios.drawInRect(CGRectMake(0, 0, newSize.width, newSize.height));
|
||||
|
||||
const resizedImage = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
|
||||
return new ImageSource(resizedImage);
|
||||
}
|
||||
}
|
||||
|
||||
function getFileName(path: string): string {
|
||||
|
Reference in New Issue
Block a user