2012-06-08 33 views
1

我想繪製一個六邊形並使用html5顯示一個圖像。 我已經嘗試過,但我沒有得到圖像作爲結果。 我只想爲此使用kineticjs用html5和kineticjs顯示六角形內的圖像

下面是代碼:

function hexagon(){ 
    var stage = new Kinetic.Stage({ 
     container: "container" 
    }); 

    var layer = new Kinetic.Layer(); 

    var hexagon = new Kinetic.RegularPolygon({ 
     x: 100, 
     y: 100, 
     sides: 6, 
     radius: 100, 
     fill: {image: "css/images/logo.png"}, 

     stroke: "royalblue", 
     strokeWidth: 2 
    }); 

    // add the shape to the layer 
    layer.add(hexagon); 
    // add the layer to the stage 
    stage.add(layer); 
} 

回答

1

填充拍攝圖像對象。請嘗試以下操作:

var layer = new Kinetic.Layer(); 

logo = new Image(); 
logo.src = "css/images/logo.png"; 

var hexagon = new Kinetic.RegularPolygon({ 
     x: 100, 
     y: 100, 
     sides: 6, 
     radius: 100, 
     fill: {image: logo}, 

     stroke: "royalblue", 
     strokeWidth: 2 
    }); 

    // add the shape to the layer 
    layer.add(hexagon); 
    // add the layer to the stage 
    stage.add(layer); 
} 
+0

它不工作。我也試圖把kineticimage的對象。但它仍然不起作用。 – Hiral

+0

調試控制檯是否告訴你任何有用的信息? –

+0

不,我只是得到一個黑色填充六邊形而不是六邊形內的圖像。該怎麼辦? – Hiral