* [task#127424] use getCanvasSize of think3c widget.

This commit is contained in:
wangzemei
2024-09-05 16:39:53 +08:00
committed by 刘刚
parent f338b05b06
commit e190fba472
+10 -28
View File
@@ -1,39 +1,21 @@
$(document).ready(function()
{
const canvas = $('#canvas')[0];
const ctx = canvas.getContext('2d');
const image = new Image();
const maxWidth = $('.think-model-content').width() || 500;
const maxHeight = maxWidth;
const canvas = $('#canvas')[0];
const ctx = canvas.getContext('2d');
const image = new Image();
image.src = modelImg;
image.onload = function()
{
let width = image.width;
let height = image.height;
const size = getCanvasSize(image.width, image.height);
canvas.width = size.width;
canvas.height = size.height;
ctx.drawImage(image, 0, 0, size.width, size.height);
if(width > maxWidth || height > maxHeight)
{
if(width > height)
{
height *= maxWidth / width;
width = maxWidth;
}
else
{
width *= maxHeight / height;
height = maxHeight;
}
}
canvas.width = width;
canvas.height = height;
ctx.drawImage(image, 0, 0, width, height);
const imageData = ctx.getImageData(0, 0, width, height);
const pixels = binarizeImage(imageData);
const imageData = ctx.getImageData(0, 0, size.width, size.height);
const pixels = binarizeImage(imageData);
ctx.putImageData(pixels, 0, 0);
};
image.src = modelImg;
/* 检查图片是否已加载完成,如未完成,手动触发处理逻辑。*/
/* Check if the image has been loaded completely. If not, manually trigger the processing logic. */