通过鼠标拖拉获取图片原像素的两个点坐标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网页的时候,有时候会考虑按照插入的图片的尺寸来判断图片是横图还是竖图.然后判断过后给予不同的展示方式! 另外一种就是在手机页面上,在新闻页插入的图片往往都 ...
随机推荐
- Go 基础之基本数据类型
Go 基础之基本数据类型 目录 Go 基础之基本数据类型 一.整型 1.1 平台无关整型 1.1.1 基本概念 1.1.2 分类 有符号整型(int8~int64) 无符号整型(uint8~uint6 ...
- Rethinking Point Cloud Registration as Masking and Reconstruction论文阅读
Rethinking Point Cloud Registration as Masking and Reconstruction 2023 ICCV *Guangyan Chen, Meiling ...
- python系列:argparse详解 外部传参给python的库
一.argparse简介 argparse 模块是 Python 内置的用于命令项选项与参数解析的模块,argparse 模块可以让人轻松编写用户友好的命令行接口,能够帮助程序员为模型定义参数. ar ...
- 累死了qwq-一些平时的思考awa
最近真的有点难受了qwq有的时候没有认可我就是会有点伤心虽然知道就算是全部的人都认可我也没有什么用...但是总归是一个动力的来源.唉有的时候真的好想就这么的放弃信奥啊,毕竟在浙江这种地方,想要那一个奖 ...
- Android Studio里导入制作好的图片后,直接报错,图片名下方出现红色波浪线
症状:Android Studio里导入制作好的图片后,直接报错,图片名下方出现红色波浪线. 比如:bk_Image_BackGround,报红 解决办法:如:bk_Image_BackGround, ...
- 实战攻防演练-WinRar压缩包创建自解压木马
前言 在攻防演练中,钓鱼攻击通常采用社会工程学手段,通过伪装成可信的来源,引导用户点击恶意链接或下载恶意文件,进而实现攻击.而使用压缩包自解压技术可以在一定程度上提高攻击成功率.其中包含的自解压木马就 ...
- mysql insert的特殊用法
1. 正常的insert语句:插入一条数据如下:INSERT INTO `testdb`.`tb_user` (`id`, `userName`) VALUES (3, '张飞'); 2. inser ...
- ALSA Compress-Offload API
概述 从 ALSA API 的早期开始,它就被定义为支持 PCM,或考虑到了 IEC61937 等固定比特率的载荷.参数和返回值以帧计算是常态,这使得扩展已有的 API 以支持压缩数据流充满挑战. 最 ...
- CVE-2017-7921 海康威视(Hikvision)摄像头漏洞复现
今天看到了海康威视又出了新漏洞--CVE-2021-36260,突然心血来潮想要复现一下,结果搜到了一个旧的漏洞--CVE-2017-7921,而且发现仍然有不少海康威视摄像头后台没有修补这个漏洞,于 ...
- IDEA提示Cannot resolve class or package ‘beans‘等类似错误
一.解决方案 1.问题原因: 2.解决: 快捷键:Alt+Enter选择.