![](/img/trans.png)
[英]how to get the real (unscaled) size of an embedded image in the svg document?!
[英]How to get real size of image and resized in Angular?
有一張圖:
@ViewChild('image')
readonly image: ElementRef;
Html:
<img #image class="image" />
CSS自動調整后如何獲得實際尺寸(寬度,高度)和調整大小?
我試過這個:
console.log(this.container.nativeElement.clientHeight);
console.log(this.container.nativeElement.clientWidth);
它返回我 500 和 0。
嘗試這個:
<img #image src="images/path" class="image" (load)="onLoad()" />
在 controller
onLoad() {
console.log((this.image.nativeElement as HTMLImageElement).width);
console.log((this.image.nativeElement as HTMLImageElement).height);
}
演示: https://stackblitz.com/edit/angular-rqceml?file=src/app/app.component.ts
你可以試試這個:
console.log((this.container.nativeElement as HTMLImageElement).naturalWidth); console.log((this.container.nativeElement as HTMLImageElement).naturalHeight);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.