第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Konva js中的線寬

Konva js中的線寬

慕桂英546537 2021-11-04 15:32:34
只需要創(chuàng)建帶有圖像背景的線條。我在這里的官方文檔中找到了這個機會(https://konvajs.org/api/Konva.Line.html)。一開始,我只需要創(chuàng)建帶有張力、顏色填充和寬度的線條,但寬度屬性不起作用(或者我不知道該怎么做)。我的代碼和輸出:let line2 = new Konva.Line({  x: 100,  y: 50,  points: [75, 75, 100, 200, 300, 140],  fill: "red",  tension: 0.5,  width: 50,  strokeWidth: 1,  stroke: 'green'});
查看完整描述

2 回答

?
開心每一天1111

TA貢獻1836條經(jīng)驗 獲得超13個贊

如另一個答案中所述,Konva@4.0.12不支持筆畫模式。但是可以使用 2d 本機畫布 API


所以你必須:


1 - 繪制自定義形狀并手動進行描邊


2 - 或者您可以使用混合模式來混合線條和圖像:


  const group = new Konva.Group();

  layer.add(group);


  // draw line

  const line = new Konva.Line({

   x: 100,

   y: 50,

   points: [75, 75, 100, 200, 300, 140],

   fill: "red",

   tension: 0.5,

   strokeWidth: 1,

   stroke: 'green'

  });

  group.add(line);


  // "fill" line with globalCompositeOperation: 'source-in' rectangle

  var lineClientRect = line.getClientRect();

  var fillRect = new Konva.Rect({

    x: lineClientRect.x,

    y: lineClientRect.y,

    width: lineClientRect.width,

    height: lineClientRect.height,

    fillPatternImage: img,

    globalCompositeOperation: 'source-in'

  });

  layer.add(fillRect);


  group.cache();

  layer.draw();

這可能有點棘手,因為globalCompositeOperation可能會影響您的線條周圍的所有形狀。為了解決這個問題,我們可以將線和“填充”矩形添加到組中并緩存它。


演示:https : //jsbin.com/zodojezuma/2/edit?html,js,output


查看完整回答
反對 回復(fù) 2021-11-04
?
慕絲7291255

TA貢獻1859條經(jīng)驗 獲得超6個贊

Konva 當(dāng)前版本 (4.0.12) 無法將圖案應(yīng)用于線條對象的筆劃。下面的代碼段使用帶有圖像填充圖案的閉合線,但我認為這不是您所追求的區(qū)域,但我創(chuàng)建它是為了查看可能的內(nèi)容,因此將在此處發(fā)布以備將來使用。


var width = window.innerWidth;

var height = window.innerHeight;


var stage = new Konva.Stage({

container: 'container',

width: width,

height: height

});


var layer = new Konva.Layer();



// add the layer to the stage

stage.add(layer);


var layer2 = new Konva.Layer();

var rect1 = new Konva.Rect({width:10, height:10, fill: 'magenta'})

var rect2 = new Konva.Rect({width:5, height:5, fill: 'cyan'})

var rect3 = new Konva.Rect({x: 5, y:5, width:5, height:5, fill: 'cyan'})


stage.add(layer2);

layer2.add(rect1);

layer2.add(rect2);

layer2.add(rect3);

stage.draw();

   

   

 // make an image out of layer2 

 // Note - be sure to include width & height when using toImage() otherwise uses size of stage and fillpatternrepeat will seem to fail.  

 var image = layer2.toImage({

    width: 10, height: 10,   

  callback(img) {

    // do stuff with img

      var blob = new Konva.Line({

        points: [23, 20, 23, 160, 70, 93, 150, 109, 290, 139, 270, 93],

        fill: '#00D2FF',

        fillPriority: 'pattern',

        stroke: 'black',

        strokeWidth: 5,

        closed: true,

        tension: 0.3

      });


  // add the shape to the layer

  layer.add(blob);

      

  stage.draw();


  var imageObj = new Image();

  imageObj.onload = function() {

    blob.fillPatternImage(imageObj);


    layer2.remove(); // no longer needed.

    

    blob.fillPatternImage(imageObj)

    layer.draw();


    stage.draw();

  };


  imageObj.src = img.src;


  }

});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/konva/4.0.12/konva.min.js"></script>


<div id="container"></div>

<img id='theImg' style='width:100px; height: 100px; border:"2px solid lime"; z-index: 10 '></img>



查看完整回答
反對 回復(fù) 2021-11-04
  • 2 回答
  • 0 關(guān)注
  • 474 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號