Browse Source

修正正确缩放图片BUG;封装标注事件

develop
陈鹏飞 3 years ago
parent
commit
976700b05b
  1. 24
      src/app/system-management/image-label2/image-label2.component.ts

24
src/app/system-management/image-label2/image-label2.component.ts

@ -54,10 +54,14 @@ export class ImageLabel2Component implements OnInit {
// 等比例缩放图片
var scale = 1;
if (img.width > center.clientWidth || img.height > center.clientHeight) {
if (img.width > img.height) {
scale = center.clientWidth / img.width;
}else {
scale = center.clientHeight / img.height;
let scaleOne = center.clientWidth / img.width;
let scaleTwo = center.clientHeight / img.height;
if (img.width * scaleOne <= center.clientWidth && img.height * scaleOne <= center.clientHeight) {
scale = scaleOne;
} else if (img.width * scaleTwo <= center.clientWidth && img.height * scaleTwo <= center.clientHeight) {
scale = scaleTwo;
} else {
scale = 0.3;
}
}
that.canvasWidth = img.width * scale;
@ -109,6 +113,12 @@ export class ImageLabel2Component implements OnInit {
// let html = document.documentElement
// let boxDiv = document.getElementsByClassName("canvasDialog")[0]
canvas.onmousedown = (e)=>{
this.canvasClickEvent(e,canvas,context);
}
}
//canvas 点击事件 标注
canvasClickEvent(e, canvas, context) {
var clickX = e.pageX - canvas.offsetLeft;
var clickY = e.pageY - canvas.offsetTop;
this.downx = clickX
@ -187,12 +197,6 @@ export class ImageLabel2Component implements OnInit {
context.strokeStyle = "#9d4dca";
context.stroke();
}
}
//canvas 点击事件 标注
canvasClickEvent(e) {
}
//判断点位是否在图形区域内
isInt(x, y) {

Loading…
Cancel
Save