简体   繁体   English

DOM中基于像素的图像处理

[英]Pixel-based manipulations of images in DOM

As part of a game which I am developing in Javascript I want to: 作为使用Javascript开发的游戏的一部分,我想要:

  1. load an image from a URL 从URL加载图像
  2. do some pixel-based manipulation to it (do some color filter operations to it, to be precise) 对它进行一些基于像素的操作(准确地说,对它进行一些滤色器操作)
  3. put the manipulated image as an <IMG> node into the dom of the html document 将经过处理的图像作为<IMG>节点放入html文档的dom

I already have a good idea how to do the first two parts - I am just going to draw the image to an invisible canvas. 我已经有了一个好主意,该如何做前两部分-我只是要将图像绘制到一个看不见的画布上。 But how can I do the last one? 但是我该怎么做最后一个呢?

I thought about extacting the raw binary data from the canvas and then convert it to a data URL. 我考虑过要从画布中提取原始二进制数据,然后将其转换为数据URL。 But this seems quite difficult to me. 但这对我来说似乎很困难。 Isn't there a more direct way to do that? 没有更直接的方法可以做到这一点吗? I have jQuery and jQueryUI available, when it helps. 当有帮助时,我有jQuery和jQueryUI可用。

canvas元素具有toDataURL()方法 ,该方法为您提供了立即可用的数据URL。

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

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