<tfoot id='2wEIR'></tfoot>

  1. <i id='2wEIR'><tr id='2wEIR'><dt id='2wEIR'><q id='2wEIR'><span id='2wEIR'><b id='2wEIR'><form id='2wEIR'><ins id='2wEIR'></ins><ul id='2wEIR'></ul><sub id='2wEIR'></sub></form><legend id='2wEIR'></legend><bdo id='2wEIR'><pre id='2wEIR'><center id='2wEIR'></center></pre></bdo></b><th id='2wEIR'></th></span></q></dt></tr></i><div id='2wEIR'><tfoot id='2wEIR'></tfoot><dl id='2wEIR'><fieldset id='2wEIR'></fieldset></dl></div>
    • <bdo id='2wEIR'></bdo><ul id='2wEIR'></ul>

    1. <small id='2wEIR'></small><noframes id='2wEIR'>

    2. <legend id='2wEIR'><style id='2wEIR'><dir id='2wEIR'><q id='2wEIR'></q></dir></style></legend>

      Fabric.js 动态裁剪单个对象

      时间:2023-06-21

      <small id='5hN1L'></small><noframes id='5hN1L'>

        <legend id='5hN1L'><style id='5hN1L'><dir id='5hN1L'><q id='5hN1L'></q></dir></style></legend>

          <tbody id='5hN1L'></tbody>
      1. <tfoot id='5hN1L'></tfoot>
        1. <i id='5hN1L'><tr id='5hN1L'><dt id='5hN1L'><q id='5hN1L'><span id='5hN1L'><b id='5hN1L'><form id='5hN1L'><ins id='5hN1L'></ins><ul id='5hN1L'></ul><sub id='5hN1L'></sub></form><legend id='5hN1L'></legend><bdo id='5hN1L'><pre id='5hN1L'><center id='5hN1L'></center></pre></bdo></b><th id='5hN1L'></th></span></q></dt></tr></i><div id='5hN1L'><tfoot id='5hN1L'></tfoot><dl id='5hN1L'><fieldset id='5hN1L'></fieldset></dl></div>

                <bdo id='5hN1L'></bdo><ul id='5hN1L'></ul>
                本文介绍了Fabric.js 动态裁剪单个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在动态添加一个矩形元素来裁剪/剪辑(使用clipTo)选定的元素,它在第一次时效果很好,但是当我在画布上添加第二个元素并开始裁剪第二个元素时,第一个元素会丢失裁剪/剪辑.下面是我的代码,有 2 个按钮 1 开始裁剪/剪辑(在要裁剪的元素上放置一个动态矩形)第二个进行裁剪/剪辑.

                I am dynamically adding a rect element to crop/clip (using clipTo) a selected element, It works perfect at the first time but when i add a second element to the canvas and begin to crop the second element the first element looses the crop/clip. Below is my code, there are 2 buttons 1 to start crop/clip (places a dynamic rect over the element to be cropped) second to do the cropping/clipping.

                $('#crop').on('click', function (event) {
                
                
                    var left = el.left - object.left;
                    var top = el.top - object.top;
                
                    left *= 1;
                    top *= 1;
                
                    var width = el.width * 1;
                    var height = el.height * 1;
                
                  object.clipTo = function (ctx) 
                  {
                        ctx.rect(-(el.width/2)+left, -(el.height/2)+top, parseInt(width*el.scaleX), parseInt(el.scaleY*height));
                  }
                
                
                
                    for(var i=0; i<$("#layers li").size();i++)
                        {
                            canvas.item(i).selectable= true;
                        }
                    disabled = true;
                
                    canvas.remove(canvas.getActiveObject());
                    lastActive = object;
                    canvas.renderAll();
                
                
                
                });
                
                $('#startCrop').on('click',function(){
                
                    canvas.remove(el);
                    if(canvas.getActiveObject())
                    {
                
                    object=canvas.getActiveObject();    
                    if (lastActive && lastActive !== object) {
                        lastActive.clipTo = null;
                    }
                
                
                
                        el = new fabric.Rect
                        ({
                            fill: 'rgba(0,0,0,0.3)',
                            originX: 'left',
                            originY: 'top',
                            stroke: '#ccc',
                            strokeDashArray: [2, 2],
                            opacity: 1,
                            width: 1,
                            height: 1,
                            borderColor: '#36fd00',
                            cornerColor: 'green',
                            hasRotatingPoint:false
                        });
                
                        el.left=canvas.getActiveObject().left;
                        selection_object_left=canvas.getActiveObject().left;
                        selection_object_top=canvas.getActiveObject().top;
                        el.top=canvas.getActiveObject().top;
                        el.width=canvas.getActiveObject().width*canvas.getActiveObject().scaleX;
                        el.height=canvas.getActiveObject().height*canvas.getActiveObject().scaleY;
                
                
                        canvas.add(el);
                        canvas.setActiveObject(el);
                        for(var i=0; i<$("#layers li").size();i++)
                            {
                                canvas.item(i).selectable= false;
                            }
                    }
                
                    else{
                            alert("Please select an object or layer");
                        }
                
                });
                

                推荐答案

                这就是你要找的吗?http://jsfiddle.net/86bTc/4/

                你设置lastActive.clipTo = null;

                这篇关于Fabric.js 动态裁剪单个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:使用 WebGL 将两个画布混合到一个上 下一篇:如何在画布上重新着色灰度图像

                相关文章

                • <bdo id='29Dfz'></bdo><ul id='29Dfz'></ul>
                <legend id='29Dfz'><style id='29Dfz'><dir id='29Dfz'><q id='29Dfz'></q></dir></style></legend>

                  <i id='29Dfz'><tr id='29Dfz'><dt id='29Dfz'><q id='29Dfz'><span id='29Dfz'><b id='29Dfz'><form id='29Dfz'><ins id='29Dfz'></ins><ul id='29Dfz'></ul><sub id='29Dfz'></sub></form><legend id='29Dfz'></legend><bdo id='29Dfz'><pre id='29Dfz'><center id='29Dfz'></center></pre></bdo></b><th id='29Dfz'></th></span></q></dt></tr></i><div id='29Dfz'><tfoot id='29Dfz'></tfoot><dl id='29Dfz'><fieldset id='29Dfz'></fieldset></dl></div>
                1. <tfoot id='29Dfz'></tfoot>
                2. <small id='29Dfz'></small><noframes id='29Dfz'>