<template>
<div>
<img
class="no-drag"
ref="image"
src="https://dashanbook.oss-cn-shenzhen.aliyuncs.com/11.png"
@mousedown="startSelection"
@mousemove="updateSelection"
@mouseup="endSelection"
height="600px"
/>
<div
v-if="showHighlightBox"
class="highlight-box"
:style="{
width: selectionWidth + 'px',
height: selectionHeight + 'px',
left: selectionLeft + 'px',
top: selectionTop + 'px',
}"
></div>
</div>
</template> <script>
export default {
data() {
return {
startX: null,
startY: null,
endX: null,
endY: null, mouseX: 0,
mouseY: 0,
selectionStartX: 0,
selectionStartY: 0,
selectionEndX: 0,
selectionEndY: 0,
showHighlightBox: false,
};
},
//获得原图片像素的的长与宽
mounted() {
const image = this.$refs.image;
image.addEventListener("load", () => {
this.naturalWidth = image.naturalWidth;
this.naturalHeight = image.naturalHeight;
});
}, methods: {
startSelection(event) {
const image = this.$refs.image;
const rect = image.getBoundingClientRect();
this.startX =
(event.clientX - rect.left) * (this.naturalWidth / image.width);
this.startY =
(event.clientY - rect.top) * (this.naturalHeight / image.height); this.selectionStartX = event.pageX;
this.selectionStartY = event.pageY;
console.log("startSelection============================");
this.showHighlightBox = true;
},
updateSelection(event) {
const image = this.$refs.image;
const rect = image.getBoundingClientRect();
this.endX =
(event.clientX - rect.left) * (this.naturalWidth / image.width);
this.endY =
(event.clientY - rect.top) * (this.naturalHeight / image.height); this.mouseX = event.pageX;
this.mouseY = event.pageY;
this.selectionEndX = this.mouseX;
this.selectionEndY = this.mouseY;
},
endSelection() {
const image = this.$refs.image;
const rect = image.getBoundingClientRect();
this.endX =
(event.clientX - rect.left) * (this.naturalWidth / image.width);
this.endY =
(event.clientY - rect.top) * (this.naturalHeight / image.height);
console.log(
`Point 1: (${this.startX},${this.startY},${this.endX},${this.endY})`
);
console.log(`Point 2: (${this.endX}, ${this.endY})`); this.showHighlightBox = false;
// calculate dimensions of highlight box and determine selected objects
},
},
computed: {
selectionWidth() {
return Math.abs(this.selectionEndX - this.selectionStartX);
},
selectionHeight() {
return Math.abs(this.selectionEndY - this.selectionStartY);
},
selectionLeft() {
return Math.min(this.selectionStartX, this.selectionEndX);
},
selectionTop() {
return Math.min(this.selectionStartY, this.selectionEndY);
},
},
};
</script> <style>
.highlight-box {
position: absolute;
border: 1px dashed black;
pointer-events: none;
}
.no-drag {
-webkit-user-drag: none;
}
</style>

通过鼠标拖拉获取图片原像素的两个点坐标vue的更多相关文章

  1. [Swift]扩展UIImage :获取图片指定像素的颜色值

    对[UIImage]进行扩展 import UIKit extension UIImage{ /** 根据坐标获取图片中的像素颜色值 */ subscript (x: Int, y: Int) -&g ...

  2. 用Delphi直接获取bmp图片的像素

    用Delphi直接获取bmp图片的像素,并存储显示出.(此像素主要用在LED上显示).希望高手能给出代码啊!! function getImagePixels(f: string): Integer; ...

  3. swift获取图片像素颜色值

    extension UIImage{ /** 获取图片中的像素颜色值 - parameter pos: 图片中的位置 - returns: 颜色值 */ func getPixelColor(pos: ...

  4. [读码][js,css3]能感知鼠标方向的图片遮罩效果

    效果图: 无意间看到过去流行的一个效果:[能感知鼠标方向的图片遮罩效果]近来不忙,就仔细的看了一看看到后来发现,网上有好多版本,谁是原著者似乎已经无法考证.读码就要读比较全面的,读像是原著的代码.代码 ...

  5. js和jquery如何获取图片真实的宽度和高度

    按照插入的图片的尺寸来判断图片是横图还是竖图.然后判断过后给予不同的展示方式,下面为大家介绍下js和jquery如何获取图片真实的宽度和高度   1.什么时候需要获取图片真实的宽度和高度 在做pc网页 ...

  6. js和jquery获取图片真实的宽度和高度

    1.什么时候需要获取图片真实的宽度和高度 在做pc网页的时候,有时候会考虑按照插入的图片的尺寸来判断图片是横图还是竖图.然后判断过后给予不同的展示方式! 另外一种就是在手机页面上,在新闻页插入的图片往 ...

  7. 获取图片工具类:BitmapUtil

    package com.example.administrator.filemanager.utils;import android.content.Context;import android.gr ...

  8. android调用系统相机并获取图片

    如果不是特别的要求,通过拍照的方式取得图片的话,我们一般调用系统的拍照来完成这项工作,而没必要再自己去实现一个拍照功能.调用系统相机很简单,只需要一个intent就可以跳转到相几界面,然后再通过onA ...

  9. android通过BitmapFactory.decodeFile获取图片bitmap报内存溢出的解决办法

    android通过BitmapFactory.decodeFile获取图片bitmap报内存溢出的解决办法 原方法: public static Bitmap getSmallBitmap(Strin ...

  10. 如何通过js和jquery获取图片真实的宽度和高度

    什么时候需要获取图片真实的宽度和高度 在做pc网页的时候,有时候会考虑按照插入的图片的尺寸来判断图片是横图还是竖图.然后判断过后给予不同的展示方式! 另外一种就是在手机页面上,在新闻页插入的图片往往都 ...

随机推荐

  1. CMake中添加 -lpthread 编译参数

    问题:当在linux命令行中编译关于进程/线程的源文件时,需要加上 -lpthread 参数动态链接线程库而在CMake中如何加入呢? 方法:只需在 add_executable() 命令前面加上以下 ...

  2. OpenSSL 生成 RootCA (根证书)并自签署证书(支持 IP 地址)

    背景 某机房内部访问需要配置 HTTPS,网上找的一些证书教程都不是特别好,有些直接生成证书,没有根 CA 的证书导致信任不了 Ubuntu 机器,有些教程只有域名生成,没有 IP 生成,有些甚至报错 ...

  3. 创建vue项目并搭建JSONSERVER

    1.该前提是你已经搭建好vue-cli脚手架,开始创建一个新项目,输入 vue init webpack demo(demo是自定义项目名). 2.cd demo 进入项目安装依赖 3.在已经创建的项 ...

  4. 聊聊RNN与seq2seq

    seq2seq模型也称为Encoder-Decoder模型.顾名思义,这个模型有两个模块--Encoder(编码器)和Decoder(解码器).编码器对输入数据进行编码,解码器对被编码的数据进行解码. ...

  5. Windows系统下,GoLand的Terminal选定Git Bash作为终端,使用其上传代码时,出现中文乱码的问题

    问题描述 按照这位博主博客写的没有完全解决乱码问题博主博客 这个博主博客是我后来发现,暂时还没去验证是否可行博主博客 解决方案 notepad++直接Free Download,然后就一直下一步就无脑 ...

  6. postgresql 最近优化的SQL集合案例、(不写过程了只记录案例,PG优化器问题还是不少)

    案例1: -- 原SQL + 执行计划: explain analyze SELECT G.PID, G.FLOW_ID, G.STATUS, G.ID, AAAAAA.INFO_ID, G.CREA ...

  7. c#利用反射获取枚举的信息

    1.将不同的枚举类型作为形参传入某函数内时,形参为Enum,在函数体内进行类型强转. private T GetEnumType<T>(object o) { T enumVal = (T ...

  8. P5318 查阅文献

    题意大概意思就是分别用dfs与bfs遍历一个图,特殊要求是从编号小的点开始遍历. 用邻接表存图,至今我也没想明白怎么才可以从编号小的点开始遍历,明白是排序,但是不知道如何排序,题解中的排序方法是:按照 ...

  9. 比较Spring Security6.X 和 Spring Security 5.X的不同

    项目使用了SpringBoot3 ,因此 SpringSecurity也相应进行了升级 版本由5.4.5升级到了6.1.5 写法上发生了很大的变化,最显著的变化之一就是对 WebSecurityCon ...

  10. 火山引擎ByteHouse:如何优化ClickHouse物化视图能力?

    更多技术交流.求职机会,欢迎关注字节跳动数据平台微信公众号,回复[1]进入官方交流群 近期,火山引擎 ByteHouse 升级了基于 ClickHouse 的物化视图能力,为解决数据量爆炸式增长带来的 ...