canvas操作图片旋转组合

canvas实现图像垂直翻转 假设这有一张养眼图片,它长这样 接着我想把照片垂直翻转一下,变成这样 翻转后体验了一把倒立的美女. 经过对比,垂直翻转后,上边和下边都互换了过来,也就是说,上边的像素根据垂直中轴对称和下边的像素进行了互换操作.猜对了,垂直翻转的关键点就是每一列的上下像素根据轴对称,跟着这个重点,我们来Look一下实现的步骤 1.获取画布上图像的像素信息 2.遍历总行数一半的每一行作为外循环(向下取整) 3.遍... 阅读详情
AI摘要

该篇文章详细描述了如何使用Vue.js和HTML5CanvasAPI在网页中实现图片的放大缩小、移动和旋转功能,包括鼠标交互和性能优化策略,适用于滚动加载的图片显示场景。

QQ2024410-17653

使用canvas对图片进行放大缩小,移动,旋转的操作
如果图片多或者其他滚动加载一类的可以明显提升性能,后续可以把视频也放进canvas播放

        1. 鼠标点击到图片上面拖动的是图片
        2. 鼠标点击到canvas空白的地方拖动的是canvas
        3. 鼠标放到canvas空白的地方滚动是放大缩小canvas
        4. 鼠标放到图片上滚动是放大缩小图片
        5. 鼠标点击一张图片然后按esc是删除当前图片 
        6. 鼠标点击一张图可以控制旋转角度
<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>canvas</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/3.3.4/vue.global.prod.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        canvas {
            background-color: antiquewhite;
        }
    </style>
</head>
<body>
    <div id="app">
        <canvas ref="canvas" 
            :width="canvasWH.width * devicePixelRatio" 
            :height="canvasWH.height * devicePixelRatio"
            @wheel="canvasWheel"
            @mousedown="canvasMouseDown"
            @mousemove="canvasMouseMove"
            @mouseup="canvasMouseUp"
            :style="{width: canvasStyleWH.width + 'px', height: canvasStyleWH.height + 'px'}"
            >
        </canvas>
        <input type="file" @change="getPicture">
        <div v-if="mouseDownPic">
            <button @click="mouseDownPic.needRotate = !mouseDownPic.needRotate">修改当前可旋转状态</button>
            当前图片是否可以旋转:{{ mouseDownPic.needRotate }} -- {{ mouseDownPic.rotate }}
            <!-- 进度条 -->
            <input type="range" @input="changeNowRange" min="0" max="360" value="0" step="1">
        </div>
    </div>
    <script >
        const { createApp, ref, reactive, onMounted  } = Vue;
        createApp({
            setup() {
                const canvas = ref();
                const ctx = ref();
                // 当前画布大小
                const canvasWH = reactive({width: 600, height: 600});
                // 当前画板大小
                const canvasStyleWH = reactive({width: 600, height: 600 });
                // 画布像素比
                const devicePixelRatio = ref(1);
                // 当前画布的偏移量
                const canvasPYLT = reactive({left: 0, top: 0});
                // 画布放大缩小的步长
                const canvasTemp = ref(1);
                // 鼠标按下
                const mouseIsDown = ref(false);
                const mouseDownXY = {x: 0, y: 0};
                const nowClickImg = ref();
                const mouseDownPic = ref();
                // 当前传入的图片列表
                const imgList = ref([]);

                /** 在canvas上绘画图片 */
                const getPicture = (e) => {
                    const files = e.target.files;
                    if(files.length){
                        const file = files[0];
                        const reader = new FileReader();
                        reader.readAsDataURL(file);
                        reader.onloadend=function(){
                            dataImg = reader.result;
                            let image = new Image();
                            image.src = dataImg;
                            image.onload = function (params) {
                                // 将图片放到canvas中间
                                let allW = canvasWH.width * devicePixelRatio.value;
                                let allH = canvasWH.height * devicePixelRatio.value;
                                let x = Math.floor((allW - image.width) / 2 - canvasPYLT.left);
                                let y = Math.floor((allH - image.height) / 2 - canvasPYLT.top);

                                // 图片的信息
                                imgList.value.unshift({image, width: image.width, height: image.height, x: x, y: y, needRotate: false, rotate: 0})
                            };
                        }
                    }
                }

                /** 将数组的某一项提取到数组第一项 */
                const moveElementToFirst = (arr, target) => {
                    const index = arr.indexOf(target);
                    if (index !== -1) {
                        arr.splice(0, 0, ...arr.splice(index, 1));
                    }
                    return arr;
                }

                /** 判断点击是不是在当前图片范围内 */
                const findClickedImage = (mouseX, mouseY) => {
                    const scaleW = canvasWH.width * devicePixelRatio.value / canvasStyleWH.width;
                    const scaleH = canvasWH.height * devicePixelRatio.value / canvasStyleWH.height;
                    for (const imageInfo of imgList.value) {
                        if(imageInfo.needRotate) {
                            // 如果当前的图片发生了旋转,需要计算一下当前的范围
                            const centerX = imageInfo.x + canvasPYLT.left + imageInfo.width / 2;
                            const centerY = imageInfo.y + canvasPYLT.top + imageInfo.height / 2;
                            const radians = imageInfo.rotate * Math.PI / 180; // 将角度转换为弧度
                            const rotationMatrix = [
                                Math.cos(radians), Math.sin(radians),
                                -Math.sin(radians), Math.cos(radians)
                            ];
                            // 点击位置到长方形中心的向量
                            const V_click = [mouseX * scaleW - centerX, mouseY * scaleH - centerY];
                            const V_rotated = [
                                rotationMatrix[0] * V_click[0] + rotationMatrix[1] * V_click[1],
                                rotationMatrix[2] * V_click[0] + rotationMatrix[3] * V_click[1]
                            ];

                            const halfWidth = imageInfo.width / 2;
                            const halfHeight = imageInfo.height / 2;
                            if( Math.abs(V_rotated[0]) <= halfWidth && Math.abs(V_rotated[1]) <= halfHeight ) {
                                return imageInfo;
                            }
                        } else {
                            if (
                                mouseX * scaleW >= imageInfo.x + canvasPYLT.left &&
                                mouseX * scaleW <= imageInfo.x + canvasPYLT.left + imageInfo.width &&
                                mouseY * scaleH >= imageInfo.y + canvasPYLT.top &&
                                mouseY * scaleH <= imageInfo.y + canvasPYLT.top + imageInfo.height
                            ) {
                                return imageInfo;
                            }
                        }
                    }
                    return null; // 没有找到包含点击坐标的图片
                }
                
                /** 给canvas添加放大缩小功能 */
                const canvasWheel = (e) => {
                    e.stopPropagation();
                    e.preventDefault();
                    nowClickImg.value = findClickedImage(e.offsetX, e.offsetY);
                    moveElementToFirst(imgList.value, nowClickImg.value); // 调整展示顺序
                    /** 判断是向上还是向下滚动 */
                    let isScrollTop = e.deltaY < 0 ? true : false;
                    let fuhao = isScrollTop ? 1 : -1;
                    if(nowClickImg.value) {
                        const scaleW = canvasWH.width * devicePixelRatio.value / canvasStyleWH.width;
                        const scaleH = canvasWH.height * devicePixelRatio.value / canvasStyleWH.height;
                        // 图片的宽高不是相同的,这里计算出来宽高比例,让图片放大缩小按照比例来
                        const imgScalc = nowClickImg.value.width / nowClickImg.value.height;
                        // 向上滚动的时候,放大图片,
                        nowClickImg.value.width += canvasTemp.value * fuhao * imgScalc;
                        nowClickImg.value.height += canvasTemp.value * fuhao;
                        // 计算当前左边和上边的百分比,计算的是图片的
                        const left = ((e.offsetX * scaleW - nowClickImg.value.x - canvasPYLT.left) / nowClickImg.value.width) * imgScalc;
                        const top = (e.offsetY * scaleH - nowClickImg.value.y - canvasPYLT.top) / nowClickImg.value.height;
                        // 然后根据当前鼠标在画布的位置进行偏移,让放大中心在鼠标位置
                        // 获取当前鼠标相对于画布的位置 offsetX offsetY
                        // 添加-1 是因为放大缩小是向相反位置移动
                        nowClickImg.value.x += left * canvasTemp.value * fuhao * -1;
                        nowClickImg.value.y += top * canvasTemp.value * fuhao * -1;
                    } else {
                        // 向上滚动的时候放大画布
                        // 放大画布
                        canvasWH.width += canvasTemp.value * fuhao / devicePixelRatio.value;
                        canvasWH.height += canvasTemp.value * fuhao / devicePixelRatio.value;
                        // 计算当前左边和上边的百分比
                        const left = e.offsetX / canvasStyleWH.width;
                        const top = e.offsetY / canvasStyleWH.height;
                        // 然后根据当前鼠标在画布的位置进行偏移,让放大中心在鼠标位置
                        // 获取当前鼠标相对于画布的位置 offsetX offsetY
                        canvasPYLT.left += left * canvasTemp.value * fuhao;
                        canvasPYLT.top += top * canvasTemp.value * fuhao;
                    }
                    // 操作完成之后把选中的图片去掉
                    nowClickImg.value = null;
                }
                /** canvas的鼠标按下 */
                const canvasMouseDown = (e) => {
                    mouseIsDown.value = true;
                    mouseDownXY.x = e.offsetX;
                    mouseDownXY.y = e.offsetY;
                    nowClickImg.value = findClickedImage(e.offsetX, e.offsetY);
                    moveElementToFirst(imgList.value, nowClickImg.value); // 调整展示顺序
                    mouseDownPic.value = nowClickImg.value; // 当前点击的项,用于esc删除
                }

                /** canvas的鼠标抬起 */
                const canvasMouseUp = (e) => {
                    mouseIsDown.value = false;
                    mouseDownXY.x = 0;
                    mouseDownXY.y = 0;
                    // 鼠标抬起的时候需要把图片像素设置成整数,避免模糊 wheel那里就不用了,避免移动的中心发生改变
                    // 如果感觉在移动的时候模糊,想要清晰,那就在移动的时候都移动到整数,但是这样会导致偏移,
                    // 所以需要在每次取整的时候把偏移量记下,等偏移量达到1的时候就加一
                    if(nowClickImg.value) {
                        nowClickImg.value.x = Math.floor(nowClickImg.value.x);
                        nowClickImg.value.y = Math.floor(nowClickImg.value.y);
                        nowClickImg.value = null;
                    }
                    canvasPYLT.left = Math.floor(canvasPYLT.left);
                    canvasPYLT.top = Math.floor(canvasPYLT.top);
                }

                /** canvas的鼠标移动 */
                const canvasMouseMove = (e) => {
                    if(mouseIsDown.value) {
                        const scaleW = canvasWH.width * devicePixelRatio.value / canvasStyleWH.width;
                        const scaleH = canvasWH.height * devicePixelRatio.value / canvasStyleWH.height;
                        if(nowClickImg.value) {
                            // 让当前点击到的图片移动
                            nowClickImg.value.x += (e.offsetX - mouseDownXY.x) * scaleW;
                            nowClickImg.value.y += (e.offsetY - mouseDownXY.y) * scaleH;
                        } else {
                            // 让canvas画布移动
                            canvasPYLT.left += (e.offsetX - mouseDownXY.x) * scaleW;
                            canvasPYLT.top += (e.offsetY - mouseDownXY.y) * scaleH;
                        }
                        mouseDownXY.x = e.offsetX;
                        mouseDownXY.y = e.offsetY;
                    }
                }

                /** 使用requestAnimationFrame保证刷新频率 */
                const drawImage = () => {
                    ctx.value.clearRect(0, 0, canvasWH.width * devicePixelRatio.value, canvasWH.height * devicePixelRatio.value);
                    // 保存当前状态
                    ctx.value.save();
                    // 平移坐标系
                    ctx.value.translate(canvasPYLT.left, canvasPYLT.top);
                    for(let i=imgList.value.length -1; i>=0; i--) {
                        let item = imgList.value[i];
                        if(item.needRotate) {
                            // 旋转图片 顺时针旋转
                            ctx.value.save();
                            ctx.value.translate(item.x + item.width / 2 , item.y + item.height / 2);
                            ctx.value.rotate(Math.PI / 180 * item.rotate);
                            ctx.value.drawImage(item.image, -item.width / 2, -item.height / 2, item.width, item.height);
                            // 恢复设置(恢复的步骤与修改的步骤向反)
                            ctx.value.rotate(-Math.PI / 180 * item.rotate);
                            ctx.value.translate(-(item.x + item.width / 2), -(item.y + item.height / 2));
                            ctx.value.restore();
                        } else {
                            // 向canvas添加图片
                            ctx.value.drawImage(item.image, item.x, item.y, item.width, item.height);
                        }
                    }
                    // 恢复之前保存的状态
                    ctx.value.restore();
                    requestAnimationFrame(drawImage);
                };
                
                // 监听按键按下,在按esc的时候删除对应的图片
                const keydown = (e) => {
                    if (event.key === 'Escape' || event.keyCode === 27) {
                        e.stopPropagation();
                        e.preventDefault();
                        if(mouseDownPic.value) {
                            imgList.value.shift();
                            mouseDownPic.value = null;
                        }
                    }
                }
                // 当前图片的旋转角度
                const changeNowRange = (e) => {
                    if(mouseDownPic.value) {
                        mouseDownPic.value.rotate = e.target.value;
                    }
                }
                onMounted(()=>{
                    ctx.value = canvas.value.getContext("2d");
                    // 获取设备像素比
                    let pixelRatio = window.devicePixelRatio || 1;
                    // 尝试获取 backingStorePixelRatio(非标准属性,可能不存在)
                    devicePixelRatio.value = pixelRatio * (ctx.value.backingStorePixelRatio || ctx.value.webkitBackingStorePixelRatio || ctx.value.msBackingStorePixelRatio || 1 ); // 若未找到,设为 1 作为默认值
                    requestAnimationFrame(drawImage);
                    document.removeEventListener("keydown", keydown);
                    document.addEventListener("keydown", keydown);
                })

                // 返回需要暴露给模板的数据和方法
                return {
                    getPicture,
                    canvasWH,
                    devicePixelRatio,
                    canvasStyleWH,
                    canvas,
                    canvasWheel,
                    canvasMouseUp,
                    canvasMouseMove,
                    canvasMouseDown,
                    mouseDownPic,
                    changeNowRange
                };
            }
        }).mount('#app');
    </script>
</body>
</html>

一种优化的方法,理论上可以上传255 * 255 * 255张图片,并且能够更方便的确定点击的图片
想要做成一个图片裁剪组件,还没做完,后面再继续做

<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>canvas</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/3.3.4/vue.global.prod.js"></script>
    <script src="./canvasClass.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        canvas {
            /* background-color: antiquewhite; */
        }
    </style>
</head>
<body>
    <div id="app">
        <canvas ref="canvas"></canvas>
        <input type="file" @change="getPicture">
        <div v-if="mouseDownPic">
            <button @click="mouseDownPic.needRotate = !mouseDownPic.needRotate">修改当前可旋转状态</button>
            <button @click="clipCanvasToImage">裁剪图片</button>
            <button @click="changeNowFlipX">x翻转</button>
            <button @click="changeNowFlipY">y翻转</button>
            当前图片是否可以旋转:{{ mouseDownPic.needRotate }} -- {{ mouseDownPic.rotate }}
            <!-- 进度条 -->
            <input type="range" @input="changeNowRange" min="0" max="360" value="0" step="1">
        </div>
        <img :src="imgSrc" alt="">
    </div>
    <script >
        const { createApp, ref, reactive, onMounted  } = Vue;
        createApp({
            setup() {
                /**
                 *  思路:
                 *  这是要做成一个canvas的功能组件,通过拿到传进来的canvas标签,来给这个canvas绑定方法
                */
                // 获取canvas标签
                const canvas = ref(null);
                // 当前画布大小
                const canvasWH = reactive({width: 208 * 10, height: 78 * 10});
                // 当前画板大小
                const canvasStyleWH = reactive({width: 600, height: 400});
                // canvas的一些处理方法
                const canvasFun = ref(null);
                const mouseDownPic = ref();
                const changeNowRange = (e) => {
                    const value = e.target.value;
                    if(mouseDownPic.value) {
                        mouseDownPic.value.rotate = value;
                    }
                }
                const changeNowFlipX = ()=>{
                  if(mouseDownPic.value) {
                      mouseDownPic.value.flipX =!mouseDownPic.value.flipX;
                  }
                }
                const changeNowFlipY = ()=>{
                  if(mouseDownPic.value) {
                      mouseDownPic.value.flipY =!mouseDownPic.value.flipY;
                  }
                }
                const imgSrc = ref('');
                const clipCanvasToImage = ()=>{
                  imgSrc.value = canvasFun.value.clipCanvasToImage();
                }
                /** 在canvas上绘画图片 */
                const getPicture = (e) => {
                    const files = e.target.files;
                    if(files.length){
                        const file = files[0];
                        const reader = new FileReader();
                        reader.readAsDataURL(file);
                        reader.onloadend=function(){
                            dataImg = reader.result;
                            let image = new Image();
                            image.src = dataImg;
                            image.onload = function (params) {
                                canvasFun.value.addImg(image)
                            };
                        }
                    }
                }
                onMounted(() => {
                    canvasFun.value = new Canvas({canvas: canvas.value,canvasWH, canvasStyleWH, mouseDownPic, canvasIsDoubleWH: true});
                });

                // 返回需要暴露给模板的数据和方法
                return {
                    canvas,
                    getPicture,
                    mouseDownPic,
                    changeNowRange,
                    clipCanvasToImage,
                    imgSrc,
                    changeNowFlipX,
                    changeNowFlipY                
                };
            }
        }).mount('#app');
    </script>
</body>
</html>

canvasClass.js

/**
 * @description: 画布类
 * @param {*} canavs: canvas对象
 * @param {*} canvasWH: canvas的宽高
 * @param {*} canvasStyleWH: canvas的样式宽高
 * @param {*} mouseDownPic: 鼠标按下图片对象
 * @param {*} canvasIsDoubleWH:画布是图片两倍宽高
 */
class Canvas {
    constructor({canvas, canvasWH, canvasStyleWH, mouseDownPic, canvasIsDoubleWH}) {
        // 获取canvas对象
        this.canvas = canvas;
        this.canvasWH = canvasWH;
        this.canvasStyleWH = canvasStyleWH;
        this.mouseDownPic = mouseDownPic;
        this.canvasIsDoubleWH = canvasIsDoubleWH;
        // 当前鼠标已经按下
        this.mouseIsDown = false;
        // 当前鼠标点击的坐标
        this.mouseDownXY = {x: 0, y: 0};
        // 当前传入的图片对象
        this.imgListMap = new Map();
        // 用于控制当前图片层级的数组
        this.imgList = [];
        // canvas的偏移量
        this.canvasPYLT = {
            left: this.canvas.offsetLeft,
            top: this.canvas.offsetTop
        };
        // 步长
        this.canvasTemp = {
            value: 10
        };
        // 当前点击到的裁剪区域 边:左上、右上、右下、左下 上 下 左 右 中间部分
        this.nowDownType = "";
        this.canvasMask = {};
        this.canvas2Image = {};
        // 当前画布添加按键绑定事件
        this.keydown();
        // 当前点击的对象 rgb
        this.clickObj = "";
        // 获取canvas上下文
        this.ctx = canvas.getContext("2d");
        // 设备像素比
        this.getDevicePixelRatio();
        // 在一开始创建一个canvas,然后在这个canvas上绘画所有的图形,但是只绘画颜色,不用使用图片填充
        // 在一开始创建一个canvas,然后把这个canvas当作主canvas的蒙版,用于绘制裁剪区域
        this.getTempCanvas();
        this.tempCanvasFun();
        // 获取canvas信息
        this.canvasResize();
        // 给canvas添加滚动放大缩小事件
        this.canvasWheel();
        this.mousedown();
        this.mousemove();
        this.mouseup();
        // 开始绘画 避免requestAnimationFrame修改this指向
        this.draw = this.draw.bind(this);
        this.draw();
        // 存储当前删除的颜色
        this.colorList = new Set();
        // 存储当前已经获取到哪一个颜色
        this.colorObj = {
            r: 1,
            g: 0,
            b: 0
        };
    }
    keydownFun(e){
        if (event.key === "Escape" || event.keyCode === 27) {
            e.stopPropagation();
            e.preventDefault();
            if(this.mouseDownPic.value) {
                const deleteStr = this.imgList.shift();
                this.imgListMap.delete(deleteStr);
                this.mouseDownPic.value = null;
            }
        }
    }
    keydown(){
        document.removeEventListener("keydown", this.keydownFun.bind(this));
        document.addEventListener("keydown", this.keydownFun.bind(this));
    }
    // #region 绘画带角度的图形
    drawRotate(ctx, item, isTemp){
        // 需要先判断一下这个图片、图形在不在当前canvas可视区域内

        ctx.save();
        ctx.translate(item.x + item.width / 2, item.y + item.height / 2);
        ctx.rotate(Math.PI / 180 * item.rotate);
        if(isTemp) {
            // 备份的canvas,只需要绘画一个填充颜色矩形的就可以
            ctx.fillStyle = item.color;
            ctx.fillRect(-item.width / 2, -item.height / 2, item.width, item.height);
        } else {
            if(item.flipX && item.flipY) {
            // 翻转图片
                this.ctx.scale(-1, -1);
            } else if(item.flipX) {
            // 翻转图片
                this.ctx.scale(-1, 1);
            } else if(item.flipY) {
            // 翻转图片
                this.ctx.scale(1, -1);
            }
            ctx.drawImage(item.image, -item.width / 2, -item.height / 2, item.width, item.height);
        }
        // 恢复设置(恢复的步骤与修改的步骤向反)
        ctx.rotate(-Math.PI / 180 * item.rotate);
        ctx.translate(-(item.x + item.width / 2), -(item.y + item.height / 2));
        ctx.restore();
    }
    // 开始绘画
    draw() {
        this.ctx.clearRect(0, 0, this.canvasWH.width * this.devicePixelRatio.value, this.canvasWH.height * this.devicePixelRatio.value);
        this.canvasTemp.ctx.clearRect(0, 0, this.canvasWH.width * this.devicePixelRatio.value, this.canvasWH.height * this.devicePixelRatio.value);
        this.canvasMask.ctx.clearRect(0, 0, this.canvasWH.width * this.devicePixelRatio.value, this.canvasWH.height * this.devicePixelRatio.value);
        this.canvasMaskAddModel();
        // 保存当前状态
        this.ctx.save();
        this.canvasTemp.ctx.save();
        // 平移坐标系
        this.ctx.translate(this.canvasPYLT.left, this.canvasPYLT.top);
        this.canvasTemp.ctx.translate(this.canvasPYLT.left, this.canvasPYLT.top);
        // 倒着绘画
        for(let i=this.imgList.length -1; i>=0; i--) {
            let item = this.imgListMap.get(this.imgList[i]);
            // 如果有旋转角度,就按照角度来旋转
            if(item.needRotate) {
                // 旋转图片 顺时针旋转
                // 展示canvas
                this.drawRotate(this.ctx, item);
                // 备份canvas
                this.drawRotate(this.canvasTemp.ctx, item, true);
            } else {
                if(item.flipX && item.flipY) {
                    // 翻转图片
                    this.ctx.save();
                    this.ctx.translate(item.x, item.y);
                    this.ctx.scale(-1, -1);
                    this.ctx.drawImage(item.image, -item.width, -item.height, item.width, item.height);
                    this.ctx.restore();
                } else if(item.flipX) {
                    // 翻转图片
                    this.ctx.save();
                    this.ctx.translate(item.x, item.y);
                    this.ctx.scale(-1, 1);
                    this.ctx.drawImage(item.image, -item.width, 0, item.width, item.height);
                    this.ctx.restore();
                } else if(item.flipY) {
                    // 翻转图片
                    this.ctx.save();
                    this.ctx.translate(item.x, item.y);
                    this.ctx.scale(1, -1);
                    this.ctx.drawImage(item.image, 0, -item.height, item.width, item.height);
                    this.ctx.restore();
                } else {
                    // 向canvas添加图片
                    this.ctx.drawImage(item.image, item.x, item.y, item.width, item.height);
                }
                // 备份canvas添加矩形
                this.canvasTemp.ctx.fillStyle = item.color;
                this.canvasTemp.ctx.fillRect(item.x, item.y, item.width, item.height);
            }
        }
        this.ctx.restore();
        this.canvasTemp.ctx.restore();
        requestAnimationFrame(this.draw);
    }
    // 用于获取一个不同颜色的函数
    getColor(){
        // 先判断colorList中有没有值
        if(this.colorList.size > 0) {
            // 获取第一个颜色
            let color = this.colorList[0];
            // 获取当前颜色
            return `rgb(${color.r}, ${color.g}, ${color.b})`;
        } else {
            // 根据this.colorObj的值来获取一个颜色
            let color = `rgb(${this.colorObj.r}, ${this.colorObj.g}, ${this.colorObj.b})`;
            // 把this.colorObj的值加1 但是需要判断是否超出范围
            this.colorObj.r += 1;
            if(this.colorObj.r > 255) {
                this.colorObj.r = 0;
                this.colorObj.g += 1;
                if(this.colorObj.g > 255) {
                    this.colorObj.g = 0;
                    this.colorObj.b += 1;
                    if(this.colorObj.b > 255) {
                        // 其实这里就是重复的颜色了,一般达不到这种情况
                        this.colorObj.b = 0;
                        // 000是画布颜色
                        this.colorObj.r = 1;
                    }
                }
            }
            return color;
        }
    }
    // 添加图片
    addImg(image) {
        if(this.canvasIsDoubleWH) {
            // 根据图片大小设置画布大小,画布大小其中的宽或者高是图片的两倍
            const width2 = image.width * 1.1;
            const height2 = image.height * 1.1;
            // 当前画板比例
            const wh = this.canvasStyleWH.width / this.canvasStyleWH.height;
            // 计算应该把画布的哪里放大
            const scaleW = this.canvasStyleWH.width / width2;
            const scaleH = this.canvasStyleWH.height / height2;
            // 将大的那边占满画板,然后把小的那边根据画板宽高比例缩放
            if(scaleW > scaleH) {
                // 宽的比例大,说明是高的那边占满画板,这时候需要把宽的那边放大
                this.canvasWH.height = height2;
                this.canvasWH.width = height2 * wh;
            } else {
                // 高的比例大,说明是宽的那边占满画板,这时候需要把高的那边放大
                this.canvasWH.width = width2;
                this.canvasWH.height = width2 / wh;
            }
            this.canvasResize();

            // 计算图片当前在画布的大小
            let allW = this.canvasWH.width * this.devicePixelRatio.value;
            let allH = this.canvasWH.height * this.devicePixelRatio.value;
            let x = Math.floor((allW - image.width) / 2 - this.canvasPYLT.left);
            let y = Math.floor((allH - image.height) / 2 - this.canvasPYLT.top);
            // 根据当前图片的宽高和当前画布的宽高,设置当前裁剪的区域为图片的区域
            this.canvasMask.styleRect = [
                x / this.canvasWH.width * this.canvasStyleWH.width,
                y / this.canvasWH.height * this.canvasStyleWH.height,
                image.width / this.canvasWH.width * this.canvasStyleWH.width,
                image.height / this.canvasWH.height * this.canvasStyleWH.height
            ];
        }
        // 将图片放到canvas中间
        let allW = this.canvasWH.width * this.devicePixelRatio.value;
        let allH = this.canvasWH.height * this.devicePixelRatio.value;
        let x = Math.floor((allW - image.width) / 2 - this.canvasPYLT.left);
        let y = Math.floor((allH - image.height) / 2 - this.canvasPYLT.top);
        // 添加的图片放到第一项
        // 添加的时候需要给当前图片添加一个颜色,用于区分当前是点击的哪个图片
        let color = this.getColor();
        const img = {image, width: image.width, height: image.height, x: x, y: y, needRotate: false, rotate: 0, color, flipX: false, flipY: false};
        this.imgListMap.set(color, img);
        this.imgList.unshift(color);
        
    }
    // #region 设备像素比
    getDevicePixelRatio() {
        // 设备像素比
        this.devicePixelRatio = {
            value: window.devicePixelRatio
        };
        let pixelRatio = window.devicePixelRatio || 1;
        // 尝试获取 backingStorePixelRatio(非标准属性,可能不存在)
        // 若未找到,设为 1 作为默认值
        let backingStorePixelRatio = this.ctx.backingStorePixelRatio || this.ctx.webkitBackingStorePixelRatio || this.ctx.msBackingStorePixelRatio || 1 ;
        this.devicePixelRatio.value = pixelRatio * backingStorePixelRatio; 
    }
    // 获取canvas基本信息
    canvasResize() {
        this.canvas.width = this.canvasWH.width * this.devicePixelRatio.value;
        this.canvas.height = this.canvasWH.height * this.devicePixelRatio.value;
        this.canvas.style.width = this.canvasStyleWH.width + "px";
        this.canvas.style.height = this.canvasStyleWH.height + "px";
        this.tempCanvasFun();
    }
    // #region 获取当前点击图片
    getMoveColor(e){
        const scaleW = this.canvasWH.width * this.devicePixelRatio.value / this.canvasStyleWH.width;
        const scaleH = this.canvasWH.height * this.devicePixelRatio.value / this.canvasStyleWH.height;
        // 获取点击位置的颜色
        const color = this.canvasTemp.ctx.getImageData(e.offsetX * scaleW, e.offsetY * scaleH, 1, 1).data;
        // 将颜色值转换为RGB格式
        if(color[0] == color[1] == color[2] == 0) {
            this.clickObj = "";
        } else {
            this.clickObj = `rgb(${color[0]}, ${color[1]}, ${color[2]})`;
            // 将点击的图片移动到最上面
            this.moveElementToFirst(this.imgList, this.clickObj);
            this.mouseDownPic.value = this.imgListMap.get(this.clickObj);
        }
    }

    // #region 鼠标滚动事件
    // 添加滚动放大缩小事件
    canvasWheel() {
        this.canvasMask.canvas.addEventListener("wheel", this.throttle((e) => {
            // 这里不能每次都触发,要加一个节流
            e.stopPropagation();
            e.preventDefault();
            // 获取当前点击的对象
            this.getMoveColor(e);
            /** 判断是向上还是向下滚动 */
            let isScrollTop = e.deltaY < 0 ? true : false;
            let fuhao = isScrollTop ? 1 : -1;
            if(this.clickObj){
                const nowClickImg = this.imgListMap.get(this.clickObj);
                const scaleW = this.canvasWH.width * this.devicePixelRatio.value / this.canvasStyleWH.width;
                const scaleH = this.canvasWH.height * this.devicePixelRatio.value / this.canvasStyleWH.height;
                // 图片的宽高不是相同的,这里计算出来宽高比例,让图片放大缩小按照比例来
                const imgScalc = nowClickImg.width / nowClickImg.height;
                // 向上滚动的时候,放大图片,
                nowClickImg.width += this.canvasTemp.value * fuhao * imgScalc;
                nowClickImg.height += this.canvasTemp.value * fuhao;
                // 计算当前左边和上边的百分比,计算的是图片的
                const left = ((e.offsetX * scaleW - nowClickImg.x - this.canvasPYLT.left) / nowClickImg.width) * imgScalc;
                const top = (e.offsetY * scaleH - nowClickImg.y - this.canvasPYLT.top) / nowClickImg.height;
                // 然后根据当前鼠标在画布的位置进行偏移,让放大中心在鼠标位置
                // 获取当前鼠标相对于画布的位置 offsetX offsetY
                // 添加-1 是因为放大缩小是向相反位置移动
                nowClickImg.x += left * this.canvasTemp.value * fuhao * -1;
                nowClickImg.y += top * this.canvasTemp.value * fuhao * -1;
            } else {
                // 向上滚动的时候放大画布
                // 放大画布
                this.canvasWH.width += this.canvasTemp.value * fuhao / this.devicePixelRatio.value;
                this.canvasWH.height += this.canvasTemp.value * fuhao / this.devicePixelRatio.value;
                // 计算当前左边和上边的百分比
                const left = e.offsetX / this.canvasStyleWH.width;
                const top = e.offsetY / this.canvasStyleWH.height;
                // 然后根据当前鼠标在画布的位置进行偏移,让放大中心在鼠标位置
                // 获取当前鼠标相对于画布的位置 offsetX offsetY
                this.canvasPYLT.left += left * this.canvasTemp.value * fuhao;
                this.canvasPYLT.top += top * this.canvasTemp.value * fuhao;
            }
            this.clickObj = "";
            this.canvasResize();
        }, 18, {leading: true, trailing: true}));
    }
    // #region 添加鼠标按下事件
    mousedown() {
        this.canvasMask.canvas.addEventListener("mousedown", (e) => {
            e.stopPropagation();
            e.preventDefault();
            this.mouseIsDown = true;
            this.mouseDownXY.x = e.offsetX;
            this.mouseDownXY.y = e.offsetY;
            // 获取当前点击的对象
            this.getMoveColor(e);
        });
    }
    // #region 鼠标canvas上抬起事件
    mouseUpCanvas(e) {
        e.stopPropagation();
        e.preventDefault();
        this.mouseIsDown = false;
        this.mouseDownXY.x = 0;
        this.mouseDownXY.y = 0;
        if(this.clickObj) {
            this.imgListMap.get(this.clickObj).x = Math.floor(this.imgListMap.get(this.clickObj).x);
            this.imgListMap.get(this.clickObj).y = Math.floor(this.imgListMap.get(this.clickObj).y);
            this.clickObj = "";
        }
        // 鼠标抬起的时候需要把图片像素设置成整数,避免模糊 wheel那里就不用了,避免移动的中心发生改变
        // 如果感觉在移动的时候模糊,想要清晰,那就在移动的时候都移动到整数,但是这样会导致偏移,
        // 所以需要在每次取整的时候把偏移量记下,等偏移量达到1的时候就加一
        this.canvasPYLT.left = Math.floor(this.canvasPYLT.left);
        this.canvasPYLT.top = Math.floor(this.canvasPYLT.top);

        // 鼠标抬起的时候,需要把裁剪区域修改一下,避免右下角拖动到了左上角的左边或者上边
        if(this.canvasMask.styleRect[2] < 0) {
            this.canvasMask.styleRect[0] += this.canvasMask.styleRect[2];
            this.canvasMask.styleRect[2] = -this.canvasMask.styleRect[2];
        }
        if(this.canvasMask.styleRect[3] < 0) {
            this.canvasMask.styleRect[1] += this.canvasMask.styleRect[3];
            this.canvasMask.styleRect[3] = -this.canvasMask.styleRect[3];
        }
    }
    // #region 添加鼠标抬起事件
    mouseup() {
        this.canvasMask.canvas.addEventListener("mouseup", (e) => {
            this.mouseUpCanvas(e);
        });
        document.addEventListener("mouseup", (e) => {
            this.mouseUpCanvas(e);
        });
    }
    // #region 鼠标canvas上移动的事件
    canvasMouseMoveFun(e) {
        if(this.mouseIsDown) {
            if(this.nowDownType == "noClipArea") {
                const scaleW = this.canvasWH.width * this.devicePixelRatio.value / this.canvasStyleWH.width;
                const scaleH = this.canvasWH.height * this.devicePixelRatio.value / this.canvasStyleWH.height;
                if(this.imgListMap.has(this.clickObj)) {
                    // 让当前点击到的图片移动
                    this.imgListMap.get(this.clickObj).x += (e.offsetX - this.mouseDownXY.x) * scaleW;
                    this.imgListMap.get(this.clickObj).y += (e.offsetY - this.mouseDownXY.y) * scaleH;
                } else {
                    // 让canvas画布移动
                    this.canvasPYLT.left += (e.offsetX - this.mouseDownXY.x) * scaleW;
                    this.canvasPYLT.top += (e.offsetY - this.mouseDownXY.y) * scaleH;
                }
                this.mouseDownXY.x = e.offsetX;
                this.mouseDownXY.y = e.offsetY;
            } else {
                if (this.nowDownType == "center") {
                    // 裁剪区域位置移动
                    const x = this.canvasMask.styleRect[0] + (e.offsetX - this.mouseDownXY.x);
                    const y = this.canvasMask.styleRect[1] + (e.offsetY - this.mouseDownXY.y);
                    if(x < 0) {
                        this.canvasMask.styleRect[0] = 0;
                    } else if(x + this.canvasMask.styleRect[2] > this.canvasStyleWH.width) {
                        console.log("不需要处理");
                        // this.canvasMask.styleRect[0] = this.canvasStyleWH.width - this.canvasMask.styleRect[2];
                    } else {
                        this.canvasMask.styleRect[0] = x;
                    }
                    if(y < 0) {
                        this.canvasMask.styleRect[1] = 0;
                    } else if(y + this.canvasMask.styleRect[3] > this.canvasStyleWH.height) {
                        console.log("不需要处理");
                        // this.canvasMask.styleRect[1] = this.canvasStyleWH.height - this.canvasMask.styleRect[3];
                    } else {
                        this.canvasMask.styleRect[1] = y;
                    }
                    this.canvasMask.canvas.style.cursor = "grabbing";
                } else if (this.nowDownType == "right") {
                    // 右边裁剪区域位置移动
                    this.canvasMask.styleRect[2] += (e.offsetX - this.mouseDownXY.x);
                    this.canvasMask.canvas.style.cursor = "ew-resize";
                } else if (this.nowDownType == "bottom") {
                    // 下边裁剪区域位置移动
                    this.canvasMask.styleRect[3] += (e.offsetY - this.mouseDownXY.y);
                    this.canvasMask.canvas.style.cursor = "ns-resize";
                } else if (this.nowDownType == "left") {
                    // 左边裁剪区域位置移动
                    this.canvasMask.styleRect[0] += (e.offsetX - this.mouseDownXY.x);
                    this.canvasMask.styleRect[2] -= (e.offsetX - this.mouseDownXY.x);
                    this.canvasMask.canvas.style.cursor = "ew-resize";
                } else if (this.nowDownType == "top") {
                    // 上边裁剪区域位置移动
                    this.canvasMask.styleRect[1] += (e.offsetY - this.mouseDownXY.y);
                    this.canvasMask.styleRect[3] -= (e.offsetY - this.mouseDownXY.y);
                    this.canvasMask.canvas.style.cursor = "ns-resize";
                } else if(this.nowDownType == "rightTop") {
                    // 右上角裁剪区域位置移动
                    this.canvasMask.styleRect[1] += (e.offsetY - this.mouseDownXY.y);
                    this.canvasMask.styleRect[3] -= (e.offsetY - this.mouseDownXY.y);
                    this.canvasMask.styleRect[2] += (e.offsetX - this.mouseDownXY.x);
                    this.canvasMask.canvas.style.cursor = "nesw-resize";
                } else if(this.nowDownType == "rightBottom") {
                    // 右下角裁剪区域位置移动
                    this.canvasMask.styleRect[2] += (e.offsetX - this.mouseDownXY.x);
                    this.canvasMask.styleRect[3] += (e.offsetY - this.mouseDownXY.y);
                    this.canvasMask.canvas.style.cursor = "nwse-resize";
                } else if(this.nowDownType == "leftTop") {
                    // 左上角裁剪区域位置移动
                    this.canvasMask.styleRect[0] += (e.offsetX - this.mouseDownXY.x);
                    this.canvasMask.styleRect[1] += (e.offsetY - this.mouseDownXY.y);
                    this.canvasMask.styleRect[2] -= (e.offsetX - this.mouseDownXY.x);
                    this.canvasMask.styleRect[3] -= (e.offsetY - this.mouseDownXY.y);
                    this.canvasMask.canvas.style.cursor = "nwse-resize";
                } else if(this.nowDownType == "leftBottom") {
                    // 左下角裁剪区域位置移动
                    this.canvasMask.styleRect[2] -= (e.offsetX - this.mouseDownXY.x);
                    this.canvasMask.styleRect[3] += (e.offsetY - this.mouseDownXY.y);
                    this.canvasMask.styleRect[0] += (e.offsetX - this.mouseDownXY.x);
                    this.canvasMask.canvas.style.cursor = "nesw-resize";
                }
                this.mouseDownXY.x = e.offsetX;
                this.mouseDownXY.y = e.offsetY;
            }
        } else {
            // 判断当前鼠标移动的位置是否是在裁剪区域的各个部分
            this.nowDownType = this.getNowDownType(e);
        }
    }
    // #region 添加鼠标移动事件
    mousemove() {
        // 鼠标在canvas上移动时让裁剪区域跟随鼠标移动
        this.canvasMask.canvas.addEventListener("mousemove", this.throttle((e)=>{
            e.stopPropagation();
            e.preventDefault();
            this.canvasMouseMoveFun(e);
        }, 18, {leading: true, trailing: true}));
        // 鼠标在canvas外移动时让裁剪区域跟随鼠标移动
        document.addEventListener("mousemove", this.throttle((e)=>{
            const canvasRect = this.canvas.getBoundingClientRect();
            // 判断当前鼠标是否在画布外面
            if(e.clientX < canvasRect.left || e.clientX > canvasRect.right || e.clientY < canvasRect.top || e.clientY > canvasRect.bottom) {
                // 鼠标在canvas外移动时让裁剪区域跟随鼠标移动
                if(this.mouseIsDown) {
                    e.stopPropagation();
                    e.preventDefault();
                    // 获取当前画布的位置
                    // 获取当前鼠标的位置
                    let mouseX = e.clientX - canvasRect.left;
                    let mouseY = e.clientY - canvasRect.top;
                    if(mouseX < canvasRect.left) {
                        mouseX = canvasRect.left;
                    } else if(mouseX > canvasRect.right) {
                        mouseX = canvasRect.right;
                    }
                    if(mouseY < canvasRect.top) {
                        mouseY = canvasRect.top;
                    } else if(mouseY > canvasRect.bottom) {
                        mouseY = canvasRect.bottom;
                    }
                    this.canvasMouseMoveFun({offsetX: mouseX, offsetY: mouseY});
                }
            }
        }, 18, {leading: true, trailing: true}));
    }
    /** 将数组的某一项提取到数组第一项 */
    moveElementToFirst(arr, target) {
        const index = arr.indexOf(target);
        if (index !== -1) {
            arr.splice(0, 0, ...arr.splice(index, 1));
        }
        return arr;
    }
    getTempCanvas(){
        // 备份的canvas,只需要绘画一个填充颜色矩形的就可以
        this.canvasTemp.canvas = document.createElement("canvas");
        this.canvasTemp.ctx = this.canvasTemp.canvas.getContext("2d");
        // 用于蒙版的canvas
        this.canvasMask.canvas = document.createElement("canvas");
        this.canvasMask.ctx = this.canvasMask.canvas.getContext("2d");
        // 用于裁剪的canvas
        this.canvas2Image.canvas = document.createElement("canvas");
        this.canvas2Image.ctx = this.canvas2Image.canvas.getContext("2d");
        // 设置传进来的canvas画布是相对定位
        this.canvas.style.position = "relative";
        // 灰白相间的方块
        // this.canvas.style.backgroundImage = `linear-gradient( 45deg, rgba(0, 0, 0, 0.5) 25%, transparent 0, transparent 75%, rgba(0, 0, 0, 0.5) 0 ), 
        // linear-gradient(135deg, rgba(0, 0, 0, 0.5) 25%, transparent 0, transparent 75%, rgba(0, 0, 0, 0.5) 0)`;
        // this.canvas.style.backgroundSize = "30px 30px";
        // // this.canvas.style.backgroundRepeat = "no-repeat";
        // this.canvas.style.backgroundColor = "#eee";
        // 设置蒙版位置
        this.canvasMask.canvas.width = this.canvas.width;
        this.canvasMask.canvas.height = this.canvas.height;
        this.canvasMask.canvas.style.position = "absolute"; // 绝对定位
        this.canvasMask.canvas.style.top = this.canvas.offsetTop + "px";
        this.canvasMask.canvas.style.left = this.canvas.offsetLeft + "px";
        this.canvasMask.canvas.style.zIndex = "1"; // 确保覆盖层在最上层
        this.canvasMask.canvas.style.backgroundColor = "transparent"; // 蒙版层背景色
        // 添上蒙版层
        this.canvas.parentNode.appendChild(this.canvasMask.canvas);

    }
    tempCanvasFun(){
        // 备份的canvas,只需要绘画一个填充颜色矩形的就可以
        this.canvasTemp.canvas.width = this.canvasWH.width * this.devicePixelRatio.value;
        this.canvasTemp.canvas.height = this.canvasWH.height * this.devicePixelRatio.value;
        this.canvasTemp.canvas.style.width = this.canvasStyleWH.width + "px";
        this.canvasTemp.canvas.style.height = this.canvasStyleWH.height + "px";
        // 用于裁剪的canvas
        this.canvasMask.canvas.width = this.canvasWH.width * this.devicePixelRatio.value;
        this.canvasMask.canvas.height = this.canvasWH.height * this.devicePixelRatio.value;
        this.canvasMask.canvas.style.width = this.canvasStyleWH.width + "px";
        this.canvasMask.canvas.style.height = this.canvasStyleWH.height + "px";
    }
    // 当前图片的旋转角度
    changeNowRange(e){
        if(this.mouseDownPic.value) {
            this.mouseDownPic.value.rotate = e.target.value;
        }
    }
    // 图片的翻转
    changeNowFlipX(e){
        if(this.mouseDownPic.value) {
            this.mouseDownPic.value.flipX = !this.mouseDownPic.value.flipX;
        }
    }
    changeNowFlipY(e){
        if(this.mouseDownPic.value) {
            this.mouseDownPic.value.flipY = !this.mouseDownPic.value.flipY;
        }
    }
    // #region model Canvas
    canvasMaskAddModel() {
        // 绘制蒙版层
        this.canvasMask.ctx.rect(0, 0, this.canvasMask.canvas.width, this.canvasMask.canvas.height);
        // this.canvasMask.ctx.fillStyle = "rgba(0,0,0,0.3)";
        // this.canvasMask.ctx.fill();
        // 绘制裁剪区域 需要保存当前裁剪窗口的画板大小
        // 然后下次绘画的时候,根据画板大小计算新的画布大小进行绘制
        if(this.canvasMask.clipRect) {
            this.canvasMask.clipRect = [
                this.canvasMask.canvas.width * this.canvasMask.styleRect[0] / this.canvasStyleWH.width,
                this.canvasMask.canvas.height * this.canvasMask.styleRect[1] / this.canvasStyleWH.height,
                this.canvasMask.canvas.width * this.canvasMask.styleRect[2] / this.canvasStyleWH.width,
                this.canvasMask.canvas.height * this.canvasMask.styleRect[3] / this.canvasStyleWH.height
            ];
        } else {
            this.canvasMask.styleRect = [this.canvasStyleWH.width/4, this.canvasStyleWH.height/4, this.canvasStyleWH.width/2, this.canvasStyleWH.height/2];
            // 根据样式大小的裁剪区域,计算出裁剪区域的大小
            this.canvasMask.clipRect = [
                this.canvasMask.canvas.width * this.canvasMask.styleRect[0] / this.canvasStyleWH.width,
                this.canvasMask.canvas.height * this.canvasMask.styleRect[1] / this.canvasStyleWH.height,
                this.canvasMask.canvas.width * this.canvasMask.styleRect[2] / this.canvasStyleWH.width,
                this.canvasMask.canvas.height * this.canvasMask.styleRect[3] / this.canvasStyleWH.height
            ];
        }

        // 单独处理图片上才能有蒙版显示
        this.canvasMask.ctx.fillStyle = "rgba(0,0,0,0.4)";
        this.imgListMap.forEach((value, key) => {
            // 绘制蒙版
            this.canvasMask.ctx.fillRect(value.x, value.y, value.width, value.height);
        });

        this.canvasMask.ctx.clearRect(this.canvasMask.clipRect[0], this.canvasMask.clipRect[1], this.canvasMask.clipRect[2], this.canvasMask.clipRect[3]);
        this.getLine({
            ctx2: this.canvasMask.ctx, 
            size: {width: this.canvasMask.clipRect[2], height: this.canvasMask.clipRect[3]}, 
            canvasModalXY: {x: this.canvasMask.clipRect[0], y: this.canvasMask.clipRect[1]}
        });
    }
    // #region 计算当前鼠标在哪个区域
    getNowDownType(e) {
        // 区域分为10个:左上角,左边,上边,右上角,右边,下边,左下角,右下角,中间 外部其他区域
        const scaleW = this.canvasWH.width * this.devicePixelRatio.value / this.canvasStyleWH.width;
        const scaleH = this.canvasWH.height * this.devicePixelRatio.value / this.canvasStyleWH.height;
        // 获取鼠标所在画布位置
        const mouseXY = {
            X: e.offsetX * scaleW,
            Y: e.offsetY * scaleH
        };
        const canvasModalSize = {
            X: this.canvasMask.canvas.width * this.canvasMask.styleRect[0] / this.canvasStyleWH.width,
            Y: this.canvasMask.canvas.height * this.canvasMask.styleRect[1] / this.canvasStyleWH.height,
            width: this.canvasMask.canvas.width * this.canvasMask.styleRect[2] / this.canvasStyleWH.width,
            height: this.canvasMask.canvas.height * this.canvasMask.styleRect[3] / this.canvasStyleWH.height
        };
        const padding = 20; // 鼠标偏移范围
        const width = 10; // 鼠标宽度
        if (mouseXY.X < canvasModalSize.X - width || mouseXY.X > canvasModalSize.X + canvasModalSize.width - width + padding) {
            this.canvasMask.canvas.style.cursor = "move";
            return "noClipArea";
        } else if (mouseXY.X < canvasModalSize.X - width + padding) {
            if (mouseXY.Y < canvasModalSize.Y - width || mouseXY.Y > canvasModalSize.Y + canvasModalSize.height - width + padding) {
                this.canvasMask.canvas.style.cursor = "move";
                return "noClipArea";
            } else if (mouseXY.Y < canvasModalSize.Y - width + padding) {
                this.canvasMask.canvas.style.cursor = "nwse-resize";
                return "leftTop";
            } else if (mouseXY.Y < canvasModalSize.Y + canvasModalSize.height - width) {
                this.canvasMask.canvas.style.cursor = "ew-resize";
                return "left";
            } else if (mouseXY.Y < canvasModalSize.Y + canvasModalSize.height - width + padding) {
                this.canvasMask.canvas.style.cursor = "nesw-resize";
                return "leftBottom";
            }
        } else if (mouseXY.X < canvasModalSize.X + canvasModalSize.width - width) {
            if (mouseXY.Y < canvasModalSize.Y - width || mouseXY.Y > canvasModalSize.Y + canvasModalSize.height - width + padding) {
                this.canvasMask.canvas.style.cursor = "move";
                return "noClipArea";
            } else if (mouseXY.Y < canvasModalSize.Y - width + padding) {
                this.canvasMask.canvas.style.cursor = "ns-resize";
                return "top";
            } else if (mouseXY.Y < canvasModalSize.Y + canvasModalSize.height - width) {
                this.canvasMask.canvas.style.cursor = "grab";
                return "center";
            } else if (mouseXY.Y < canvasModalSize.Y + canvasModalSize.height - width + padding) {
                this.canvasMask.canvas.style.cursor = "ns-resize";
                return "bottom";
            }
        } else if (mouseXY.X < canvasModalSize.X + canvasModalSize.width - width + padding) {
            if (mouseXY.Y < canvasModalSize.Y - width || mouseXY.Y > canvasModalSize.Y + canvasModalSize.height - width + padding) {
                this.canvasMask.canvas.style.cursor = "move";
                return "noClipArea";
            } else if (mouseXY.Y < canvasModalSize.Y - width + padding) {
                this.canvasMask.canvas.style.cursor = "nesw-resize";
                return "rightTop";
            } else if (mouseXY.Y < canvasModalSize.Y + canvasModalSize.height - width) {
                this.canvasMask.canvas.style.cursor = "ew-resize";
                return "right";
            } else if (mouseXY.Y < canvasModalSize.Y + canvasModalSize.height - width + padding) {
                this.canvasMask.canvas.style.cursor = "nwse-resize";
                return "rightBottom";
            }
        } 
        return "noClipArea";
    }
    // #region model画线
    /**
     * @param {*} data 要执行的函数 ctx2 画布 size裁剪宽高 canvasModalXY 画线起始位置 x,y坐标
     * @returns
     */
    getLine(data) {
        const { ctx2, size, canvasModalXY } = data;
        /** 给空白处画上虚线 */
        // 1.将空白处横向竖向分成三部分
        const lineNumber = 3;
        // 基础线宽,根据宽高大的那边来定
        let baseLineWidth = 1;
        if (this.canvasWH.width > this.canvasWH.height) {
            baseLineWidth = this.canvasWH.width / 700;
        } else {
            baseLineWidth = this.canvasWH.height / 700;
        }
        // 当前画线的比率,有些图片像素高,需要更粗的线段 向上取整
        const lineRatio = this.canvasWH.width / this.canvasWH.height;
        // 这里处理横纵两条线显示的一样宽
        let lineRatioX = 1; // 横线比率
        let lineRatioY = 1; // 竖线比率
        let lineDashX = 10; // 横线间隔
        let lineDashY = 10; // 竖线间隔
        if (lineRatio >=1) {
            // 宽度大,高度小,说明横线更细,竖线需要更粗
            lineRatioX = 1;
            lineRatioY = lineRatio;
            // 要想看起来一样,需要处理下横线竖线间隔
            lineDashX = 10 * lineRatio;
            lineDashY = 10;
        } else {
            // 宽度小,高度大,说明竖线更细,横线需要更粗
            lineRatioX = 1 / lineRatio;
            lineRatioY = 1;
            // 要想看起来一样,需要处理下横线竖线间隔
            lineDashX = 10;
            lineDashY = 10 * lineRatio;
        }
        /** 每一行的高度、宽度 */
        const xLineSpace = size.height / lineNumber;
        const yLineSpace = size.width / lineNumber;
        /** 划线起始位置,减去0.5画的更清楚 */
        const yBeginLine = canvasModalXY.x - 0.5;
        const xBeginLine = canvasModalXY.y - 0.5;
        // y轴
        for (let i = 0; i < lineNumber + 1; i++) {
            // 画y轴
            ctx2.beginPath();
            ctx2.lineWidth = 1 * lineRatioY * baseLineWidth;
            ctx2.setLineDash([lineDashY * baseLineWidth, lineDashY * 0.4 * baseLineWidth]);
            ctx2.moveTo(yBeginLine + i * yLineSpace - 0.5, xBeginLine);
            ctx2.lineTo(yBeginLine + i * yLineSpace - 0.5, xBeginLine + size.height);
            ctx2.strokeStyle = "#409EFF";
            ctx2.stroke();
  
            // 画x轴
            ctx2.beginPath();
            ctx2.lineWidth = 1 * lineRatioX * baseLineWidth;
            ctx2.setLineDash([lineDashX * baseLineWidth, lineDashX * 0.4 * baseLineWidth]);
            ctx2.moveTo(yBeginLine, xBeginLine + i * xLineSpace - 0.5);
            ctx2.lineTo(yBeginLine + size.width, xBeginLine + i * xLineSpace - 0.5);
            ctx2.strokeStyle = "#409EFF";
            ctx2.stroke();
        }
        // 在四个角画对号 左上 右上 右下 左下
        const pointMove = 5; // 距离四个角的xy距离
        const lineWidth = 30; // 线长
        const strokeArr = [
            {
                moveTo: { X: yBeginLine - pointMove + lineWidth, Y: xBeginLine - pointMove },
                lineToOne: { X: yBeginLine - pointMove, Y: xBeginLine - pointMove },
                lineToTwo: { X: yBeginLine - pointMove, Y: xBeginLine - pointMove + lineWidth }
            },
            {
                moveTo: {
                    X: yBeginLine + size.width + pointMove - lineWidth,
                    Y: xBeginLine - pointMove
                },
                lineToOne: { X: yBeginLine + size.width + pointMove, Y: xBeginLine - pointMove },
                lineToTwo: {
                    X: yBeginLine + size.width + pointMove,
                    Y: xBeginLine - pointMove + lineWidth
                }
            },
            {
                moveTo: {
                    X: yBeginLine + size.width + pointMove - lineWidth,
                    Y: xBeginLine + lineNumber * xLineSpace + pointMove
                },
                lineToOne: {
                    X: yBeginLine + size.width + pointMove,
                    Y: xBeginLine + lineNumber * xLineSpace + pointMove
                },
                lineToTwo: {
                    X: yBeginLine + size.width + pointMove,
                    Y: xBeginLine + lineNumber * xLineSpace + pointMove - lineWidth
                }
            },
            {
                moveTo: {
                    X: yBeginLine - pointMove,
                    Y: xBeginLine + size.height + pointMove - lineWidth
                },
                lineToOne: { X: yBeginLine - pointMove, Y: xBeginLine + size.height + pointMove },
                lineToTwo: {
                    X: yBeginLine - pointMove + lineWidth,
                    Y: xBeginLine + size.height + pointMove
                }
            }
        ];
        strokeArr.forEach((item) => {
            ctx2.beginPath();
            ctx2.lineWidth = 4;
            ctx2.setLineDash([0, 0]);
            ctx2.moveTo(item.moveTo.X, item.moveTo.Y);
            ctx2.lineTo(item.lineToOne.X, item.lineToOne.Y);
            ctx2.lineTo(item.lineToTwo.X, item.lineToTwo.Y);
            ctx2.strokeStyle = "#999";
            ctx2.stroke();
        });
    }
    // #region 图片裁剪
    clipCanvasToImage(){
        const image3 = new Image();
        const canvasModalSize = {
            X: this.canvasMask.canvas.width * this.canvasMask.styleRect[0] / this.canvasStyleWH.width,
            Y: this.canvasMask.canvas.height * this.canvasMask.styleRect[1] / this.canvasStyleWH.height,
            width: this.canvasMask.canvas.width * this.canvasMask.styleRect[2] / this.canvasStyleWH.width,
            height: this.canvasMask.canvas.height * this.canvasMask.styleRect[3] / this.canvasStyleWH.height
        };
        const image1Data = this.ctx.getImageData(canvasModalSize.X, canvasModalSize.Y, canvasModalSize.width, canvasModalSize.height);
        this.canvas2Image.canvas.height = canvasModalSize.height;
        this.canvas2Image.canvas.width = canvasModalSize.width;
        this.canvas2Image.ctx.clearRect(0, 0, this.canvas2Image.width, this.canvas2Image.height);
        this.canvas2Image.ctx.putImageData(image1Data, 0, 0);
        image3.src = this.canvas2Image.canvas.toDataURL("image/png");
        return image3.src;
    }
    // #region 节流函数
    /**
     * @param {*} fn 要执行的函数
     * @param {*} interval 时间间隔
     * @param {*} options 可选参数: leading第一次是否执行, trailing 最后一次是否执行
     * @returns
     */
    throttle(fn, interval, options = {leading: true, trailing: false,}) {
        const { leading, trailing } = options;
        // 1.记录上一次的开始时间
        let lastTime = 0;
        let timer = null;

        // 2.事件触发时, 真正执行的函数
        const _throttle = function (...args) {
            // 2.1.获取当前事件触发时的时间
            const nowTime = new Date().getTime();
            //当lastTime为0时且第一次不执行
            if (!lastTime && !leading) lastTime = nowTime;

            // 2.2.使用当前触发的时间和之前的时间间隔以及上一次开始的时间, 计算出还剩余多长事件需要去触发函数
            const remainTime = interval - (nowTime - lastTime);
            if (remainTime <= 0) {
                if (timer) {
                    //执行函数时,需要取消定时器
                    clearTimeout(timer);
                    timer = null;
                }

                // 2.3.真正触发函数
                fn.apply(this, args);
                // 2.4.保留上次触发的时间
                lastTime = nowTime;
                return;
            }

            //当最后一次需要执行且没有定时器时,只需要创建一个定时器,还有多久触发由remainTime决定
            if (trailing && !timer) {
                timer = setTimeout(() => {
                    fn.apply(this, args);
                    timer = null; //执行后重置
                    lastTime = !leading ? 0 : new Date().getTime(); //第一次不执行时为0,第一次执行时为定时器执行时的时间
                }, remainTime);
            }
        };
        return _throttle;
    }

}

// export default Canvas;


基于H5实现图片剪切缩放旋转与预览功能 随着移动互联网的发展,用户对网页中图片交互体验的要求日益提高,H5(HTML5)技术为前端图片处理提供了强大支持。通过<canvas>元素结合FileReader和Ajax等技术,开发者可以在浏览器端实现图片的剪切、缩放、旋转与实时预览等操作,而无需依赖后端处理。与传统的图片处理方式相比,H5技术显著降低了服务器压力,提升了用户体验和页面响应速度。本章将从应用场景出发,介绍H5图片处理的核心技术流程,并探讨jQuery插件集成与移动端适配等关键问题。 阅读详情

相关推荐

LabVIEW与MySQL实时数据存储:传感器采集与数据库同步实践

本文详细介绍了如何将LabVIEW与MySQL结合,实现传感器数据的实时采集与高效存储。通过设计合理的数据库表结构、配置LabVIEW数据库连接工具包,并编写核心的采集与存储VI,构建了稳定可靠的数据链路。文章重点分享了批量插入、连接管理、时间同步等关键优化技巧与避坑指南,帮助工程师应对工业监控、环境监测等场景下的实时数据同步挑战。

weixin_29281915的博客 270

canvas图片旋转,图片base64编码,保存图片

canvas图片旋转,图片base64编码,保存图片

芝芝为荔枝 4679

卫星载荷应用方案

本文将从技术和应用层面探讨卫星载荷的应用方案,分析各个领域的特点和挑战,以期为卫星载荷的应用提供一定的指导和参考。卫星载荷应用方案涵盖了通信、地球观测、气象预报、导航定位等诸多领域在每一个领域中,都存在着不同的技术挑战和应用需求。随着技术的进步和需求的变化,卫星载荷应用方案将不断发展和完善,为人类社会的进步和发展做出更大的贡献。用户可以通过接收多颗卫星的信号,计算自身的位置和速度信息。在覆盖扩展方面,可以采用多星座、MEO、GEO 等不同轨道高度的卫星布局,结合卫星的特点和应用需求,实现覆盖范围的扩展。

muyangjun的专栏 913

canvas旋转

canvas旋转的两种方法: 1、先用translate()将(0,0)坐标移动到想要旋转的中心点,再用rotate()旋转,最后要用translate()将中心移回(0,0)点。 2、将要旋转的内容放在save()方法和restore()方法之间(类似于将两个方法里的绘制放在新的画布里),此方法也要用translate()方法移动(0,0)点,再用rotate()方法。 注意:

soooyoung的博客 1977

伯德图详解:从传递函数到系统稳定性的频域分析

在自动控制与控制系统设计中,理解系统对不同频率输入信号的响应特性,是分析和设计稳定系统的核心基础。频率响应描述了系统对正弦输入的幅值增益与相位变化规律,而伯德图作为最直观的频域分析工具,通过对数坐标将宽频带特性压缩成一条清晰曲线,让工程师无需复杂计算即可快速评估系统性能。从典型环节的渐近线绘制,到相位裕度、幅值裕度的读取,伯德图贯穿了系统稳定性判断、控制器参数整定及噪声抑制等关键场景。本文结合实际调试经验,系统讲解伯德图的绘制原理与读图方法,帮助读者快速掌握从传递函数到工程应用的核心技能。

weixin_34535286的博客 357

Google Earth Engine——使用STARFM 图像融合算法将Landsat 和 MODIS 融合得出2000-2023 NDVI长时序图(空间分辨率为 30 米、时间分辨率为 16 天)

非本地入侵物种是全球生态系统面临的主要威胁之一。野葛(Pueraria montana)是一种生长迅速的藤本植物,原产于亚洲,现已入侵美国一些地区,因此该物种的管理成为一个重要问题。利用 Landsat 和 MODIS 平台收集的数据,计算了 2000 年至 2015 年肯塔基州三个侵扰地点的归一化差异植被指数(NDVI)估算值。使用 STARFM 图像融合算法将大地遥感卫星和 MODIS 得出的 NDVI 结合成空间分辨率为 30 米、时间分辨率为 16 天的时间序列。

此星光明博客 2521

Canvas 画布的旋转

这个方法是又Canvas的context提供的,它接收一个参数,这个参数指的是当前绘图顺时针旋转的角度,如上面代码所示,rotate方法的参数是“Math.PI / 6”,所以绘图应该会沿顺时针方向旋转30度。首选,我定义了一个1000*1000的正方形画布,然后在画布上绘制了两条交叉的分割线,用来定位整个画布的中心点,也是我希望围绕着旋转的中心点。上图就是最终渲染出来的效果,这是目前我想到的一种解决办法,还是感觉有点不太满意,大家有比较好的解决办法吗?如果希望绘图按照逆时针方向旋转呢?

Dominic_W的博客 3392

搞定ESD(五):静电放电问题分析与调试

前面深入分析了静电放电的干扰机理、耦合路径,从现在开始将进入下一个大家非常关注的环节:静电放电问题分析与调试,掌握静电放电问题的分析方法,快速锁定敏感设备或者耦合路径,可以达到事半功倍的效果。

记得诚 2804

canvas入门(六)旋转、偏移、缩放

欢迎查看canvas第七节内容,本节内容主要介绍canvas的translate、scale、rotate三种方法 canvas之rotate <script type="text/javascript"> window.onload = function(){ var canvas = document.getElementsByTagName('canvas')[0]; ...

风舞红枫的个人博客 5769

LVGL 磁罗盘效果

环境:LVGL 9.x + SDL2,窗口 1280×800。界面文案用英文(默认 Montserrat,无 CJK)。本文按实现顺序讲:先建立两个耦合转动体,再把磁倾角误差从卡面倾斜里推出来,最后用同一套投影把刻度、数字和目标画到卡上。画面上的迟滞、涡流、摆动和读数偏差都来自方程,没有补间动画。

摸鱼专家 143

OpenStack ussuri 私有云平台搭建企业级实战

openstack是一个云操作系统,这个操作系统控制着数据中心中的计算,存储和网络资源。所有这些资源的管理都是通过API来来实现的,并且管理资源都有相应的认证机制。在openstack中有一个叫做dashboard的仪表盘,这个仪表盘通过web界面可以管理这些在DC中的资源。除了能提供IaaS功能外,你还可以使用orchestration,错误管理和服务管理等服务来确保应用的高可用性。

悦分享 2343

canvas旋转图片(javascript)

最近在项目中需要用canvas旋转图片,这方面一开始也比较不懂。找了很多的资料才搞定这个问题。主要用到了三个函数,translate、rotate、drawImage。  translate(x,y):移动画布坐标系统,x和y表示水平和竖直方向的偏移量。  rotate(reg):旋转图片,reg表示旋转的度数。比如:Math.PI/4 表示为45。  drawImage(source,sx

feniuben的专栏 2179

深入理解鸿蒙输入子系统驱动:HDI接口、HAL层与内核驱动的协同机制

/ 扫描输入设备// 打开指定输入设备// 关闭指定输入设备// 获取指定设备信息// 获取所有设备列表鸿蒙输入子系统驱动采用分层架构设计,通过HDI接口层实现硬件抽象,HAL层提供统一的事件处理机制,用户空间驱动层负责设备管理和事件分发。整个系统支持多种输入设备类型,包括触摸屏、按键、鼠标、键盘等,并提供了完整的HID设备支持。分层架构:清晰的层次划分,便于维护和扩展事件驱动:基于epoll的高效事件处理机制设备管理:完善的设备生命周期管理HID支持。

m0_67505153的博客 219

canvas和svg整理笔记

Canvas画布 位图 1,不要在style中给canvas设置宽高,会有位移差 2, 3,fillRect()绘制一个填充的方块,默认颜色是黑色。 strokeRect()绘制带边框的方块。 绘制线条: moveTo()绘制线段的起点。 lineTo()绘制线段的令点。 每个线条只能有一个moveTo可以有多个lineTo Stroke()绘制线段 beginPath()...

weixin_30439067的博客 133

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Canvas(三-关于绘图的一些技巧2)

坐标变换: 就是改变画布的原点坐标了 import QtQuick 2.9 import QtQuick.Window 2.2 Window { visible: true width: 240 height: 120 title: qsTr("Hello World") Item { anchors.fill: parent Canvas{ id:root anchors.fi

Jack Zheng's Blog 226

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

canvas 闭合_Canvas框架-FabricJS简介

简介Fabric是一个强大而简单的JS Canvas库,我们能通过使用它实现在Canvas上创建、填充图形、给图形填充渐变颜色。 组合图形(包括组合图形、图形文字、图片等)等一系列功能。简单来说我们可以通过使用Fabric从而以较为简单的方式实现较为复杂的Canvas功能官网文档地址:http://fabricjs.com/docs/github地址:https://github.com/fabr...

weixin_32821257的博客 358

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

自定义View--(4)Path/Canvas

参考: Canvas类的最全面详解 - 自定义View应用系列

zhujunhua2012的专栏 315

java bitmap源码_drawbitmap.java

package com.androidbook.Drawing;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics.Color;import ...

weixin_42498909的博客 179

Canvas-图片旋转

Canvas-图片旋转 众所周知canvas是位图,你可以在里面渲染你要的东西,不过你只能操作canvas的属性来进行编辑。就是说你并不能操作画进canvas的东西,例如我在canvas里添加一幅画,...

weixin_39037804的博客 644

Canvas图片手势编辑:拖拽缩放旋转的工程化实现

Canvas图片交互并非简单的DOM操作,而是涉及触摸事件归一化、坐标系映射与矩阵变换的底层工程问题。原生touch事件存在多点ID管理混乱、浏览器兼容性差、preventDefault时机难控等痛点,导致手势逻辑极易出错。AlloyFinger作为轻量级Touch事件翻译器,将原始触点数据标准化为scale、rotation、centerX/Y等可计算参数,大幅降低手势开发门槛。结合Canvas 2D上下文的坐标转换、transform矩阵手动更新及屏幕→Canvas→图片三级坐标映射,可稳定实现高精度图

weixin_34377919的博客 282

jquery-cropper图片处理:旋转、缩放、翻转等高级操作指南

想要为你的网站添加专业级的图片编辑功能吗?jquery-cropper 是一个基于 Cropper.js 的 jQuery 插件,提供了完整的图片裁剪、旋转、缩放和翻转功能。这个强大的工具让开发者能够轻松实现复杂的图片处理需求,无论是头像上传、产品图片编辑还是内容管理系统,都能完美胜任。😊 ## 📦 快速安装与基础配置 首先,你需要安装 jquery-cropper 及其依赖项。通过 np

gitblog_00632的博客 929

canvas在舞台上点击后图片旋转_canvas入门之路

HTML5 的标准已经出来好久了,但是似乎其中的 Canvas 现在并没有在太多的地方用到。但是,Canvas 的优点也是很明显的,例如在绘制含有大量元素的图表的时候,SVG 往往因为性能问题而无法胜任,例如我见过的一次技术分享会的抽奖环节,虽然效果比较炫,但因为每个头像都是 DOM,利用 CSS3 控制的动画,导致了性能非常低下。使用 Canvas说了这么多,Canvas 究竟是个啥?...

weixin_39612297的博客 286

使用Canvas绘制旋转动画

在使用Canvas绘制旋转动画时我们会遇到一个问题:使用context.rotate();是将画布进行旋转,而并不是画布上的绘制的图形,那我们要怎样做才能使画布上图形旋转呢?

aKey的博客 1537

Android实现图片触摸旋转(附带源码)

Android实现图片触摸旋转(附带源码)

欢迎来到我的博客!这里是一个专注于计算机技术的分享平台,涵盖编程开发、算法研究、系统架构、软件工程等多个领域。无论你是初学者还是资深开发者,都能在这里找到有价值的内容。 1447

html5原生canvas内image旋转

目前理解下来就是旋转的不是image本身,而是要drawImage的那个canvas的2d context,context本身的绘制就是把图片本来的样子draw出来,至于旋转,透明度之类的效果都是对context在操作。 至于做到让image绕自身中心店改变角度的做法,就是让context坐标转换,并且让context改变角度,context.rotate()方法接受根据角度转换之后的...

228

bitmap 图片组合

原来做到过的类似图片 组合 ,叠加效果 (save, restore)//将2张图片合并,叠加,平铺 public Bitmap drawIntoBitmap(Bitmap src, Bitmap inbm){ // 另外创建一张组合后的图片 Bitmap newb = Bitmap.createBitmap(src.getWidth(), src.getHeight(),

1110
上一篇: 图片固定可点击位置
LiuXiaodong2020
博客等级 码龄7年 17粉丝 21原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值