Warning message for broken advanced screenshots

This commit is contained in:
JannisX11 2024-10-27 21:36:19 +01:00
parent 033cdca61a
commit 2c5d6f97c2
3 changed files with 18 additions and 0 deletions

View File

@ -349,6 +349,14 @@ const Screencam = {
img_frame.ctx.drawImage(img, 0, 0, options.resolution[0] * sample_factor, options.resolution[1] * sample_factor, 0, 0, options.resolution[0] * sample_factor, options.resolution[1] * sample_factor);
frame.ctx.drawImage(img_frame.canvas, 0, 0, options.resolution[0] * sample_factor, options.resolution[1] * sample_factor, 0, 0, options.resolution[0], options.resolution[1]);
if (frame.isEmpty() && options.resolution[0] * options.resolution[1] > 2_000_000) {
Blockbench.showMessageBox({
translateKey: 'screenshot_too_large',
icon: 'broken_image'
})
return false;
}
Screencam.returnScreenshot(frame.canvas.toDataURL(), cb);
} else {

View File

@ -248,6 +248,8 @@
"message.screenshot.title": "Screenshot",
"message.screenshot.clipboard": "Clipboard",
"message.screenshot.right_click": "Right click or long press the screenshot to copy",
"message.screenshot_too_large.title": "Screenshot Resolution Issue",
"message.screenshot_too_large.message": "The screenshot could not be rendered successfully. Please try again with a lower resolution or without supersampling.",
"message.invalid_file.title": "Invalid File",
"message.invalid_file.message": "Could not open json file: %0",
"message.invalid_file.merge_conflict": "The file contains unresolved Git merge conflicts.",

View File

@ -111,4 +111,12 @@ class CanvasFrame {
this.canvas = copy.canvas;
this.ctx = copy;
}
isEmpty() {
let {data} = this.ctx.getImageData(0, 0, this.canvas.width, this.canvas.height);
for (let i = 0; i < data.length; i += 4) {
let alpha = data[i+3];
if (alpha) return false;
}
return true;
}
}