提交 d75f300f 编写于 作者: Q qq_41923622

Thu Feb 6 18:16:00 CST 2025 inscode

上级 cfe67751
...@@ -7,24 +7,9 @@ import {fabric} from 'fabric'; ...@@ -7,24 +7,9 @@ import {fabric} from 'fabric';
import ArrowClass from '../helpers/Arrow'; import ArrowClass from '../helpers/Arrow';
function annotationsInit(imgData,canvas,historyRef,){ function annotationsInit(imgData,canvas,historyRef,positionInfo){
// 获取当前图片和画布尺寸
const currentImageWidth = canvas.backgroundImage.width;
const currentImageHeight = canvas.backgroundImage.height;
const currentCanvasWidth = canvas.getWidth();
const currentCanvasHeight = canvas.getHeight();
let imageWidth = imgData.imageWidth||imgData.imgWidth;
let imageHeight = imgData.imageHeight||imgData.imgHeight;
// 计算缩放比例
const originalScaleX = imgData.originalCanvasWidth / imageWidth;
const originalScaleY = imgData.originalCanvasHeight / imageHeight;
const currentScaleX = currentCanvasWidth / currentImageWidth;
const currentScaleY = currentCanvasHeight / currentImageHeight;
const scaleX = currentScaleX / originalScaleX;
const scaleY = currentScaleY / originalScaleY;
const { scaleX,scaleY} = positionInfo
console.log("scaleX,scaleY ",scaleX,scaleY,currentCanvasWidth,currentCanvasHeight,currentImageWidth,currentImageHeight,imageWidth,imageHeight,imgData) console.log("scaleX,scaleY ",scaleX,scaleY,currentCanvasWidth,currentCanvasHeight,currentImageWidth,currentImageHeight,imageWidth,imageHeight,imgData)
// 遍历标注信息,重新创建元素并添加到画布上 // 遍历标注信息,重新创建元素并添加到画布上
imgData.annotations.forEach((annotation) => { imgData.annotations.forEach((annotation) => {
...@@ -136,25 +121,41 @@ export const useUpload = () => { ...@@ -136,25 +121,41 @@ export const useUpload = () => {
const canvas = canvasInstanceRef.current; const canvas = canvasInstanceRef.current;
if(canvasEl?.current&&typeof e === 'string'){ if(canvasEl?.current&&typeof e === 'string'){
let imgObj = new Image(); let imgObj = new Image();
if(imgData){
// 获取当前图片和画布尺寸
const currentImageWidth = canvas.backgroundImage.width;
const currentImageHeight = canvas.backgroundImage.height;
const currentCanvasWidth = canvas.getWidth();
const currentCanvasHeight = canvas.getHeight();
let imageWidth = imgData.imageWidth||imgData.imgWidth;
let imageHeight = imgData.imageHeight||imgData.imgHeight;
// 计算缩放比例
/** const newScaleFactor = Math.min(currentCanvasWidth / img.width, currentCanvasHeight / img.height); const originalScaleX = imgData.originalCanvasWidth / imageWidth;
img.set({ const originalScaleY = imgData.originalCanvasHeight / imageHeight;
left: 0, const currentScaleX = currentCanvasWidth / currentImageWidth;
top: 0, const currentScaleY = currentCanvasHeight / currentImageHeight;
scaleX: newScaleFactor,
scaleY: newScaleFactor
});**/
imgObj.src = e as string;
initBackGroundImage(e as string, true, () => {
historyRef.current.updateCanvasState(ACTION.add);
setTimeout(()=>{
if(imgData){
annotationsInit(imgData,canvas,historyRef); const scaleX = currentScaleX / originalScaleX;
const scaleY = currentScaleY / originalScaleY;
const newScaleFactor = Math.min(currentCanvasWidth / imageWidth, currentCanvasHeight / imageHeight);
annotationsInit(imgData,canvas,historyRef,{
scaleX,
scaleY,
});
} }
}) })
},5000); } else{
}
imgObj.src = e as string;
initBackGroundImage(e as string, true, () => {
historyRef.current.updateCanvasState(ACTION.add);
return; return;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册