feat(ImageSource): resize method (#8678)

This commit is contained in:
Ken Southerland
2020-06-29 22:17:39 -07:00
committed by GitHub
parent b5b2db9093
commit bd12bafb4a
6 changed files with 86 additions and 0 deletions

View File

@ -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 {