仅使用 toDataURL 操作像素

发布于 2024-08-24 07:42:18 字数 276 浏览 7 评论 0原文

我遇到的问题是:我需要能够使用 Javascript 动态对图像进行着色,但我无法通过画布访问像素数据。但是,我可以存储 dataURL(或任何其他基于文本的数据格式)并将其包含在代码中,操作该数据,然后使用该 dataURL 创建图像对象。

我的问题是,在仅给出 dataURL 的情况下,如何访问每个像素的 RGBA 值。我假设我需要解码 base64 url​​,但是要解码成什么格式才能在像素级别上进行操作?那么是否会像将其重新编码为 base64、将其放入 url 并传递到图像一样简单?

谢谢。

The problem I have is this: I need to be able to dynamically tint an image using Javascript, but I cannot access pixel data via the canvas. I can, however, store the dataURL (or any other text-based data format) and include that with the code, manipulate that data, and then create an image object using that dataURL.

My question is, how can I access the RGBA value of each pixel, given only the dataURL. I assume I need to decode the base64 url, but into what format in order to manipulate on the pixel level? And then would be it be as trivial as re-encoding it as base64, slapping it in a url, and the passing to an image?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人生百味 2024-08-31 07:42:18

我已经在 xda 实现了 toDataURL/PNG 替换,可以满足您的需求。它在 RGBA 数组上运行,因此您可以将图像作为未压缩的资源包含在内,使用简单的 XMLHttpRequest 将其加载到数组中,对其进行操作,最后将其输入到该函数中以获得可绘制的 DataURL

http://forum.xda-developers.com/showthread.php?t=1251575

I've implemented a toDataURL/PNG replacement over at xda that may serve your needs. It operates on an RGBA array, so you could include your image as an uncompressed resource, load it into an array using a simple XMLHttpRequest, manipulate it and finally feed it into that function to get a drawable DataURL

http://forum.xda-developers.com/showthread.php?t=1251575

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文