<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. xshell无法调用gdc

    现象: <topprod:/u1/topprod/tiptop> exe2 p_zzExecute program:p_zz<topprod:/u1/topprod/tiptop&g ...

  2. tmai

    天猫精灵技能应用平台合作协议 发布日期:2020年03月18日 更新日期:2021年02月01日 鉴于您(语音技能.小程序或应用程序APP等的制作.提供或开发者)希望入驻或与天猫精灵技能应用平台(又称 ...

  3. 在 Rust 中 gRPC 使用的 protobuf 实现条件编译服务器和客户端(tonic)

    前言 Rust 中 gRPC 最优秀的库是 tonic.tonic-build 的默认生成方式是生成一个带有数据类型和客户端与服务端源码,而对于分层应用,客户端尽可能不要知道服务端的代码,同时服务端也 ...

  4. Shuffle 题解

    Shuffle 题目大意 给定一个长度为 \(n\) 的 01 序列 \(a\),你可以进行至多一次以下操作: 选定 \(a\) 的一个连续段,满足连续段内恰好有 \(k\) 个 \(1\),将该连续 ...

  5. Chromium Mojo通信

    Mojo 是一个跨平台 IPC 框架,它诞生于 chromium ,用来实现 chromium 进程内/进程间的通信.目前,它也被用于 ChromeOS. 在我们代码应用中,如何使用Mojo来作进程间 ...

  6. 21.4 Python 使用GeoIP2地图定位

    GeoIP2是一种IP地址定位库,它允许开发人员根据IP地址查找有关位置和地理位置的信息.它使用MaxMind公司的IP地址数据库,并提供一个方便的Python API.GeoIP2可以用于许多不同的 ...

  7. "科来杯"第十届山东省大学生网络安全技能大赛决赛复现WP

    从朋友那里得来的附件,感觉题目有意思,简单复现一下 MISC 简单编码 1.题目信息 0122 061 1101011 0172 0122 0105 061 1011010 0127 0154 014 ...

  8. 2023寒鹭Tron-CTF迎新赛 CRYPTO Misc 全WP

    CRYPTO 简简单单 1.题目信息 U2FsdGVkX1+2gTXPuTetdM1p+IETUDXAHe2eC33jQfgdJoOmmrJq 2.解题方法 兔子密码,在线工具直接解 简简单单2 1. ...

  9. 数据结构-线性表-单循环链表(使用尾指针)(c++)

    目录 单循环链表 说明 注意 (一)无参构造函数 (二)有参构造函数 (三)析构函数 (四)获取长度 (五)打印数组 (六)获取第i个元素的地址 (七)插入 (八)删除 (九)获取值为x的元素的位置 ...

  10. 线程的查看方式&运行原理

    观察多个线程同时运行 主要是理解 交替执行 谁先谁后,不由我们控制 查看进程线程的方法 windows 任务管理器可以查看进程和线程数,也可以用来杀死进程 tasklist 查看进程 taskkill ...