@@ -133,12 +133,10 @@ export class ImageRenderer {
133
133
ctx . clip ( ) ;
134
134
135
135
// 预计算完整块和边界块的数量,避免重复计算
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 ) ;
140
138
141
- // 1. 优先绘制所有完整的块(最常见的情况,无需边界计算)
139
+ // 绘制所有的块,无需考虑边界
142
140
for ( let row = 0 ; row < fullRows ; row ++ ) {
143
141
const drawY = y + row * imgHeight ;
144
142
for ( let col = 0 ; col < fullCols ; col ++ ) {
@@ -147,37 +145,6 @@ export class ImageRenderer {
147
145
}
148
146
}
149
147
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
-
181
148
ctx . restore ( ) ;
182
149
}
183
150
0 commit comments