CamanJS - change underlying canvas after applying filters/manipulations

僤鯓⒐⒋嵵緔 提交于 2019-11-30 05:01:47

问题


CamanJS is a great library for doing live image manipulation in the browser.

I am using Caman on a pre-existing canvas object. I may need to change the image on that canvas if a user goes 'back' to a previous area of my site and then comes forward to the canvas again.

Caman appears to cache the first image data it receives and then 'locks' the canvas to its context. Attempts to change the canvas after applying Caman result in no visible change to the canvas.

How can we change our canvas data outside of Caman and then re-apply Caman filters?


回答1:


I emailed Ryan (creator of CamanJS) and he replied that there's a function called reloadCanvasData() that can be called to 'refresh' Caman's image data cache with any changes to the canvas's original context. Here's the source link: https://github.com/meltingice/CamanJS/blob/master/src/core/caman.coffee#L387-L392

This worked perfectly: store the Caman instance you create for your canvas and then call .reloadCanvasData() on any subsequent runs. You'll then need to re-apply any Caman manipulations you desire.

I wanted to document this function as google doesn't appear to contain any references to it yet.



来源:https://stackoverflow.com/questions/20481081/camanjs-change-underlying-canvas-after-applying-filters-manipulations

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