From 284d078de8dc3c6ceecf3e77db75ab467ee2bf5f Mon Sep 17 00:00:00 2001 From: Arcai Date: Sat, 20 Sep 2025 19:30:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(graphic/Image):=E4=BF=AE=E5=A4=8D=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E6=9C=AA=E5=8A=A0=E8=BD=BD=E6=97=B6=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=B0=BA=E5=AF=B8=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当图片尚未加载完成时,确保下次能获取到正确的尺寸值。通过在检测到图片未就绪时将 _rect 设为 null,从而触发重新计算。 --- src/graphic/Image.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/graphic/Image.ts b/src/graphic/Image.ts index e1e9a05da..437b02f1c 100644 --- a/src/graphic/Image.ts +++ b/src/graphic/Image.ts @@ -8,6 +8,7 @@ import BoundingRect from '../core/BoundingRect'; import { ImageLike, MapToType } from '../core/types'; import { defaults, createObject } from '../core/util'; import { ElementCommonState } from '../Element'; +import {isImageReady} from "./helper/image"; export interface ImageStyleProps extends CommonStyleProps { image?: string | ImageLike @@ -117,7 +118,14 @@ class ZRImage extends Displayable { style.x || 0, style.y || 0, this.getWidth(), this.getHeight() ); } - return this._rect; + + const rect = this._rect; + //If the image hasn't loaded, ensure to obtain the correct value next time. + if (this.__image && !isImageReady(this.__image)) { + this._rect = null + } + + return rect; } }