@@ -133,12 +133,10 @@ export class ImageRenderer {
133133 ctx . clip ( ) ;
134134
135135 // 预计算完整块和边界块的数量,避免重复计算
136- const fullCols = Math . floor ( width / imgWidth ) ;
137- const fullRows = Math . floor ( height / imgHeight ) ;
138- const hasPartialCol = width % imgWidth > 0 ;
139- const hasPartialRow = height % imgHeight > 0 ;
136+ const fullCols = Math . ceil ( width / imgWidth ) ;
137+ const fullRows = Math . ceil ( height / imgHeight ) ;
140138
141- // 1. 优先绘制所有完整的块(最常见的情况,无需边界计算)
139+ // 绘制所有的块,无需考虑边界
142140 for ( let row = 0 ; row < fullRows ; row ++ ) {
143141 const drawY = y + row * imgHeight ;
144142 for ( let col = 0 ; col < fullCols ; col ++ ) {
@@ -147,37 +145,6 @@ export class ImageRenderer {
147145 }
148146 }
149147
150- // 2. 处理右边界的部分列(如果存在)
151- if ( hasPartialCol ) {
152- const partialWidth = width - fullCols * imgWidth ;
153- const partialColX = x + fullCols * imgWidth ;
154-
155- // 完整行的部分列
156- for ( let row = 0 ; row < fullRows ; row ++ ) {
157- const drawY = y + row * imgHeight ;
158- ctx . drawImage ( img , 0 , 0 , partialWidth , imgHeight , partialColX , drawY , partialWidth , imgHeight ) ;
159- }
160-
161- // 右下角的部分块(如果底边界也是部分的)
162- if ( hasPartialRow ) {
163- const partialHeight = height - fullRows * imgHeight ;
164- const partialRowY = y + fullRows * imgHeight ;
165- ctx . drawImage ( img , 0 , 0 , partialWidth , partialHeight , partialColX , partialRowY , partialWidth , partialHeight ) ;
166- }
167- }
168-
169- // 3. 处理底边界的部分行(如果存在)
170- if ( hasPartialRow ) {
171- const partialHeight = height - fullRows * imgHeight ;
172- const partialRowY = y + fullRows * imgHeight ;
173-
174- // 完整列的部分行
175- for ( let col = 0 ; col < fullCols ; col ++ ) {
176- const drawX = x + col * imgWidth ;
177- ctx . drawImage ( img , 0 , 0 , imgWidth , partialHeight , drawX , partialRowY , imgWidth , partialHeight ) ;
178- }
179- }
180-
181148 ctx . restore ( ) ;
182149 }
183150
0 commit comments