通过鼠标拖拉获取图片原像素的两个点坐标vue
<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的更多相关文章
- [Swift]扩展UIImage :获取图片指定像素的颜色值
		对[UIImage]进行扩展 import UIKit extension UIImage{ /** 根据坐标获取图片中的像素颜色值 */ subscript (x: Int, y: Int) -&g ... 
- 用Delphi直接获取bmp图片的像素
		用Delphi直接获取bmp图片的像素,并存储显示出.(此像素主要用在LED上显示).希望高手能给出代码啊!! function getImagePixels(f: string): Integer; ... 
- swift获取图片像素颜色值
		extension UIImage{ /** 获取图片中的像素颜色值 - parameter pos: 图片中的位置 - returns: 颜色值 */ func getPixelColor(pos: ... 
- [读码][js,css3]能感知鼠标方向的图片遮罩效果
		效果图: 无意间看到过去流行的一个效果:[能感知鼠标方向的图片遮罩效果]近来不忙,就仔细的看了一看看到后来发现,网上有好多版本,谁是原著者似乎已经无法考证.读码就要读比较全面的,读像是原著的代码.代码 ... 
- js和jquery如何获取图片真实的宽度和高度
		按照插入的图片的尺寸来判断图片是横图还是竖图.然后判断过后给予不同的展示方式,下面为大家介绍下js和jquery如何获取图片真实的宽度和高度 1.什么时候需要获取图片真实的宽度和高度 在做pc网页 ... 
- js和jquery获取图片真实的宽度和高度
		1.什么时候需要获取图片真实的宽度和高度 在做pc网页的时候,有时候会考虑按照插入的图片的尺寸来判断图片是横图还是竖图.然后判断过后给予不同的展示方式! 另外一种就是在手机页面上,在新闻页插入的图片往 ... 
- 获取图片工具类:BitmapUtil
		package com.example.administrator.filemanager.utils;import android.content.Context;import android.gr ... 
- android调用系统相机并获取图片
		如果不是特别的要求,通过拍照的方式取得图片的话,我们一般调用系统的拍照来完成这项工作,而没必要再自己去实现一个拍照功能.调用系统相机很简单,只需要一个intent就可以跳转到相几界面,然后再通过onA ... 
- android通过BitmapFactory.decodeFile获取图片bitmap报内存溢出的解决办法
		android通过BitmapFactory.decodeFile获取图片bitmap报内存溢出的解决办法 原方法: public static Bitmap getSmallBitmap(Strin ... 
- 如何通过js和jquery获取图片真实的宽度和高度
		什么时候需要获取图片真实的宽度和高度 在做pc网页的时候,有时候会考虑按照插入的图片的尺寸来判断图片是横图还是竖图.然后判断过后给予不同的展示方式! 另外一种就是在手机页面上,在新闻页插入的图片往往都 ... 
随机推荐
- 编译python为可执行文件遇到的问题:使用python-oracledb连接oracle数据库时出现错误:DPY-3010
			错误原文: DPY-3010: connections to this database server version are not supported by python-oracledb in ... 
- [最优化DP]决策单调性
			决策单调性的概念&证明工具: 决策单调性,是在最优化dp中的可能出现的一种性质,利用它我们可以降低转移的复杂度. 首先dp中会有转移,每个状态都由若干个状态转移而来,最优化dp比较特殊,只能由 ... 
- 【ZJCTF 2019】NiZhuanSiWei
			[ZJCTF 2019]NiZhuanSiWei 收获 file_get_contents绕过 include联想伪协议 熟悉__tostring魔术方法的使用 题目 代码: <?php $te ... 
- kubeadm 工具部署 kubernetes v1.16.2
			环境准备 3个节点,以下基于 Centos 7.6 系统, 内核版本:3.10.0-957.12.2.e17.x86_64 HOST NODE CPU MEM 192.168.1.111 master ... 
- 使用 mt19937 生成区间随机数
			#include <cstdio> #include <random> #include <ctime> using namespace std; int main ... 
- 使用 Jenkins + Github + dokcer-compose 部署项目-实战篇
			使用 Jenkins + Github + dokcer-compose 部署项目-实战篇 需要声明的一点是,此处实现的项目自动构建原理是 Github+Jenkins 的 webhook,因此得保证 ... 
- windows文件搜索;文件预览;全文搜索,只需myso就够了
			简介 现在提到windows文件搜索,大家可能会想到Everything.Listary.AnyTXT这三款工具,它们各有自己的专长,不能相互替代,需要安装至少两款才能高效的搜索电脑文件.现在向大 ... 
- hci0 command 0xfc20 tx timeout(Realtek 8761B Chipset, Bluetooth 5.0)
			当前使用的Linux内核版本: 4.4.189 插上USB Bluetooth 5.0 Adapter后,dmesg显示如下log: [ 240.348480] usb 3-1.2: new full ... 
- GPTs Hunter 是什么?
			原文: https://openaigptguide.com/openai-gpts-hunter/ GPTs Hunter 是一个功能强大的免费导航网站,支持多语言,提供用户友好的界面. GPTs ... 
- 【scipy 基础】--稀疏矩阵
			稀疏矩阵是一种特殊的矩阵,其非零元素数目远远少于零元素数目,并且非零元素分布没有规律.这种矩阵在实际应用中经常出现,例如在物理学.图形学和网络通信等领域. 稀疏矩阵其实也可以和一般的矩阵一样处理,之所 ... 
