MCPcopy Create free account
hub / github.com/32comic/image2pixel-web / loadImage

Method loadImage

pixelizer.js:161–190  ·  view source on GitHub ↗
(file)

Source from the content-addressed store, hash-verified

159 }
160
161 async loadImage(file) {
162 try {
163 // 显示处理控制面板
164 this.showProcessingControls();
165
166 // 创建图片对象
167 const img = new Image();
168 const imageDataUrl = await this.fileToDataUrl(file);
169
170 return new Promise((resolve, reject) => {
171 img.onload = async () => {
172 this.originalImage = img;
173 this.displayOriginalImage(img);
174 await this.autoDetectAndSuggest(img);
175
176 // 自动处理图片
177 setTimeout(() => {
178 this.processImage();
179 }, 500); // 稍微延迟确保UI更新完成
180
181 resolve(img);
182 };
183 img.onerror = reject;
184 img.src = imageDataUrl;
185 });
186 } catch (error) {
187 console.error('Error loading image:', error);
188 this.showError('图片加载失败,请检查文件格式');
189 }
190 }
191
192 fileToDataUrl(file) {
193 return new Promise((resolve, reject) => {

Callers 2

handleDropMethod · 0.95
handleFileSelectMethod · 0.95

Calls 6

fileToDataUrlMethod · 0.95
displayOriginalImageMethod · 0.95
autoDetectAndSuggestMethod · 0.95
processImageMethod · 0.95
showErrorMethod · 0.95

Tested by

no test coverage detected