<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. Ubuntu 22.04上安装docker方法及oracle 11g方法

    1.切换到管理员登录 ubt2204@ubt2204-Virtual-Machine:~/database$ su Password: 2.执行安装docker命令 root@ubt2204-Virt ...

  2. android studio error

    Invalid method receiver.: Invalid method receiver.java.lang.IllegalStateException: Invalid method re ...

  3. RAC 环境中 gc block lost 和私网通信性能问题的诊断

    声明:此文来自于MOS(Doc ID 1674865.1),整理在此以便于大家阅读学习. ■ 概要 在Oracle的RAC环境中,数据库会收集global cache 的工作负载统计信息,并把这些信息 ...

  4. ida反汇编失败

    options->general->打开堆栈指针(stack pointer) 可见反汇编失败提示的地址(本程序为00101481,原本此处不为000)处堆栈指针不为0,因此需要修改 al ...

  5. windows系统和IE的兼容性问题

    IE浏览器用户正在逐步减少,但是以前的基数较大,为了解决win和ie的版本混乱问题,特记录一下:      一.从操作系统角度出发: XP最高支持到IE8,XP支持ie6,ie7,ie8 WIN7自带 ...

  6. 使用Kali Linux进行主机发现实验

    主机发现 [实训目的] 掌握主机扫描的工作原理,学会使用ping等扫描工具,发现网络当中活跃的主机. [场景描述] 在虚拟机环境下配置4个虚拟系统"Win XP1" "W ...

  7. Python拆分列中文和 字符

    需求描述:我们日常实际的工作中经常需要把一列数据按中文和 数字或者字母单独拆分出来 导入所需的库: import pandas as pd 定义函数 extract_characters,该函数接受三 ...

  8. Linux g++减小可执行文件大小

    去掉参数-g,产生不带有调试信息的可执行文件 加上参数-O2,产生尽可能小和尽可能快的代码 strip 可执行文件 去掉目标文件中的一些符号表.调试符号表信息,以减小程序的大小 参考文献: g++重要 ...

  9. JAVA类的加载(4) ——类之间能够隔离&类占用的资源能回收

    一.类加载体系

  10. 基于.NET、Uni-App开发支持多平台的小程序商城系统 - CoreShop

    前言 小程序商城系统是当前备受追捧的开发领域,它可以为用户提供一个更加便捷.流畅.直观的购物体验,无需下载和安装,随时随地轻松使用.今天给大家推荐一个基于.NET.Uni-App开发支持多平台的小程序 ...