I want to create an online drawing tool using fabric js deployed in a PHP web page.Most of the customized tools of fabric,js, i created successfully.
But i cannot create Eraser tool like in MS Paint eraser..
I found this alternative method for eraser.This will do mask whilte color in the object
function eraser() {
mode = 'pencil';
canvas.isDrawingMode = true;
canvas.freeDrawingBrush.width = strokeWidth;
canvas.freeDrawingBrush.color = 'white';
}
But, I want to create an eraser similar to MS Paint. I checked in SO, In Fabric js there is no built in eraser
Plz any one help me.
Is it possible to make eraser in fabric js?.
if not possible, Can you suggest any easy alternative of fabric js, like any open source/free web drawing tool which will support the function of eraser.
I want to create an online drawing tool using fabric js deployed in a PHP web page.Most of the customized tools of fabric,js, i created successfully.
But i cannot create Eraser tool like in MS Paint eraser..
I found this alternative method for eraser.This will do mask whilte color in the object
function eraser() {
mode = 'pencil';
canvas.isDrawingMode = true;
canvas.freeDrawingBrush.width = strokeWidth;
canvas.freeDrawingBrush.color = 'white';
}
But, I want to create an eraser similar to MS Paint. I checked in SO, In Fabric js there is no built in eraser
Plz any one help me.
Is it possible to make eraser in fabric js?.
if not possible, Can you suggest any easy alternative of fabric js, like any open source/free web drawing tool which will support the function of eraser.
Share Improve this question edited May 23, 2017 at 10:29 CommunityBot 11 silver badge asked May 20, 2015 at 8:40 SattanathanSattanathan 4639 silver badges24 bronze badges2 Answers
Reset to default 2Unfortunately fabric.js does not support this functionality. I think the best way to do this is drawing with the background color, like this example: http://fabricjs./freedrawing/
However I found this great example: http://jsfiddle/ArtBIT/WUXDb/1/
var x = e.pageX - this.offsetLeft;
var y = e.pageY - this.offsetTop;
var radius = 10; // or whatever
var fillColor = '#ff0000';
ctx.globalCompositeOperation = 'destination-out';
ctx.fillCircle(x, y, radius, fillColor);
I hope this helps.
This possibility exists, however you should reverse the action for when you just draw:
//eraser
canvas.on('path:created', function (opt) {
opt.path.globalCompositeOperation = 'destination-out';
opt.path.lineWidth = strokeWidth;
opt.path.stroke = 'rgba(0,0,0,0)';
//opt.path.fill = 'black';
canvas.requestRenderAll();
});
//draw
canvas.on('path:created', function (opt) {
opt.path.globalCompositeOperation = 'source-over';
opt.path.lineWidth = strokeWidth;
opt.path.stroke = 'black';
//opt.path.fill = 'black';
canvas.requestRenderAll();
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744906489a4600288.html
评论列表(0条)