캔버스에 이미지를 추가 한 다음 이미지 상단에 텍스트를 추가하려고합니다. 텍스트는 텍스트 입력에 바인드됩니다. 문제는 내가 필드를 다시 그리는 대신 텍스트를 입력 할 때 자체 복제한다는 것입니다.캔버스. AngularJS. 텍스트 및 이미지 추가
내 지시어 :
.directive('memeimage', function() {
return {
restrict: 'A',
link: function (scope, el, attrs) {
scope.upperText = "";
scope.fontsize = 50;
scope.drawCanvas = function() {
var canvas = el[0];
var context = canvas.getContext("2d");
context.font = scope.fontsize + "px Impact";
context.fillStyle = 'white';
context.strokeStyle = 'black';
var x = canvas.width/2;
var y = canvas.height/6;
context.textAlign = 'center';
context.fillText(scope.upperText.toUpperCase(), x, y);
context.lineWidth = 2;
context.strokeText(scope.upperText.toUpperCase(), x, y);
};
}
}
});
여기 바이올린 : http://jsfiddle.net/HB7LU/5085/
어떻게 이런 일을 피하기 위해 텍스트를 복제하지? 동일한 캔버스에서 이미지를 사용하기 때문에 캔버스를 지우는 것은 불가능합니다.
감사합니다.
오버랩 여러 캔버스 요소? 하나는 텍스트 용이고 다른 하나는 이미지 용입니까? 이렇게하면 텍스트를 지울 수 있고 이미지가 그대로 유지됩니다. –
결과 캔버스를 그 후에 하나의 png 이미지로 변환 할 수 있습니까? –