Where is a way to apply a filter in the overlayImage?

戏子无情 提交于 2019-12-11 01:28:22

问题


I would like to apply a filter in the overlayImage. the only way to do it, is appling the filter in the whole canvas after render?


回答1:


There's no built-in support for this, but it's fairly easy to "hack".

var overlayImageUrl = '...';

// load overlay image first
fabric.Image.fromURL(overlayImageUrl, function(oImg) {

  // add and apply filter to overlay image 
  oImg.filters.push(new fabric.Image.filters.Grayscale());
  oImg.applyFilters();

  // set <img> element of fabric.Image instance 
  // and assign it directly to canvas' "overlayImage"
  canvas.overlayImage = oImg.getElement();

  // render canvas for overlayImage to appear
  canvas.renderAll();
});


来源:https://stackoverflow.com/questions/13538460/where-is-a-way-to-apply-a-filter-in-the-overlayimage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!