简体   繁体   English

jCanvas - 背景图像消失

[英]jCanvas - background image disappears

im use this http://projects.calebevans.me/jcanvas/ and im have simple example我使用这个http://projects.calebvans.me/jcanvas/并且我有简单的例子

    <input type="button" class="bt" value="draw"/><br>
  <canvas id="picture" width=1350 height=1350></canvas> 

and js和js

var canvas = document.getElementById("picture");
 var ctx = canvas.getContext('2d');
    var img = new Image(); 
    img.src = "tank_usa.jpg"; 
    img.onload = function(){
         ctx.drawImage(img, 0, 0);
    }
$(".bt").on("click",function(){
// Draw a resizable image
$('#picture').addLayer({
  type: 'image',
  draggable: true,
  source: 'facesSmall.png',
  fillStyle: '#fff',
  strokeStyle: '#c33',
  strokeWidth: 2,
  x: 180, y: 150,
  width: 200, height: 125,
  handle: {
    type: 'arc',
    fillStyle: '#fff',
    strokeStyle: '#c33',
    strokeWidth: 2,
    radius: 10
  }
})
.drawLayer();
})

if im click on button bt,and hover canvas div, my background disappears how i can do what new image draw over background如果我点击按钮 bt,然后悬停画布 div,我的背景就会消失,我该如何在背景上绘制新图像

Your background gets erased because you are using ctx.drawImage , which does not create a jCanvas layer.您的背景被擦除,因为您使用的是ctx.drawImage ,它不会创建 jCanvas 层。 jCanvas layers and non-layers cannot exist on the same canvas, because when jCanvas redraws the canvas (manually via drawLayers() or automatically when events are triggered), non-layers will be erased. jCanvas 图层和非图层不能存在于同一个画布上,因为当 jCanvas 重绘画布时(通过drawLayers()手动或触发事件时自动),非图层将被擦除。

To fix this, simply draw "tank_usa.jpg" like you drew 'facesSmall.png' : using addLayer with type: 'image' set.为了解决这个问题,简单地得出"tank_usa.jpg"像你画'facesSmall.png' :使用addLayertype: 'image'集。

$('#picture').addLayer({
    type: 'image',
    source: 'tank_usa.jpg',
    x: 0, y: 0,
    fromCenter: false
});
$(".bt").on("click",function(){
    // Draw a resizable image
    $('#picture').addLayer({
        type: 'image',
        draggable: true,
        source: 'facesSmall.png',
        fillStyle: '#fff',
        strokeStyle: '#c33',
        strokeWidth: 2,
        x: 180, y: 150,
        width: 200, height: 125,
        handle: {
            type: 'arc',
            fillStyle: '#fff',
            strokeStyle: '#c33',
            strokeWidth: 2,
            radius: 10
        }
    })
    .drawLayer();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM