我在使用Python Flask Framework的程序中遇到此问题,当我使用@ViewChild('canvas') public canvas: ElementRef;
ImagesWidth: number = 32;
ImagesHeight: number = 32;
images: string = "../assets/blackBoards/Balllmage_";
imageExtension: string = ".png"
@Input() public width = 600;
@Input() public height = 500;
private cx: CanvasRenderingContext2D;
public ngAfterViewInit()
{
const canvasEl: HTMLCanvasElement = this.canvas.nativeElement;
this.cx = canvasEl.getContext('2d')!;
let image = new Image();
canvasEl.width = this.width;
canvasEl.height = this.height;
image.onload = () => {
this.cx.drawImage(image, 0, 0, this.width, this.height);
}
image.src = require("../assets/blackBoards/NCAA_mhalfcourt_500x410.png");
let j = 0;
for (j = 0; j < 6; j++) {
let myimages = new Image();
let v = j * this.ImagesHeight;
myimages.onload = () => {
this.cx.drawImage(myimages, 0, v, this.ImagesWidth, this.ImagesHeight);
}
myimages.src = require("../assets/blackBoards/BallImage_" + j + ".png");
}
时,它不会执行return
。我尝试将for loop
语句移到return
内,在for loop
语句中对齐,但总是遇到同样的问题。
我多次搜索过这个问题,我总是看到if
语句应该在return
之后不在里面。
这就是我所做的,但它仍然是一样的。
for loop