MCPcopy Index your code
hub / github.com/zxlie/FeHelper / addScreenShot

Function addScreenShot

apps/screenshot/content-script.js:156–212  ·  view source on GitHub ↗

* 添加截图到canvas * @param {Object} data - 截图数据 * @param {string} uri - 图片URI

(data, uri)

Source from the content-addressed store, hash-verified

154 * @param {string} uri - 图片URI
155 */
156 function addScreenShot(data, uri) {
157 // 如果已取消截图,不处理
158 if (isCancelled) return;
159
160 const image = new Image();
161
162 // 图片加载错误处理
163 image.onerror = function() {
164 captureConfig.fail('图片加载失败');
165 releaseResources();
166 };
167
168 image.onload = function() {
169 try {
170 data.image = {width: image.width, height: image.height};
171
172 // 调整缩放比例
173 if (data.windowWidth !== image.width) {
174 const scale = image.width / data.windowWidth;
175 data.x *= scale;
176 data.y *= scale;
177 data.totalWidth *= scale;
178 data.totalHeight *= scale;
179 }
180
181 // 如果是第一张截图,初始化canvas
182 if (!screenshots.length) {
183 screenshots = _initScreenshots(data.totalWidth, data.totalHeight);
184 }
185
186 // 获取与当前区域重叠的canvas并绘制图像
187 const matchingScreenshots = _filterScreenshots(
188 data.x, data.y, image.width, image.height, screenshots
189 );
190
191 matchingScreenshots.forEach(screenshot => {
192 screenshot.ctx.drawImage(
193 image,
194 data.x - screenshot.left,
195 data.y - screenshot.top
196 );
197 });
198
199 // 如果是最后一步,调用成功回调
200 if (data.complete === 1) {
201 captureConfig.success(data);
202 isCapturing = false;
203 }
204 } catch (e) {
205 captureConfig.fail('处理截图时出错: ' + e.message);
206 releaseResources();
207 }
208 };
209
210 // 设置图片源
211 image.src = uri;
212 }
213

Callers

nothing calls this directly

Calls 3

releaseResourcesFunction · 0.85
_initScreenshotsFunction · 0.85
_filterScreenshotsFunction · 0.85

Tested by

no test coverage detected