可以使用javascript更改图像调色板吗? [英] Possible to change an image color palette using javascript?

查看:92
本文介绍了可以使用javascript更改图像调色板吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在这里看到了一些与此有关的问题,但是没有一个问题提供了很好的答案.

I've seen some questions about this here already but none of them provide a good answer.

我需要的是一个javascript(或者可能是使用PHP/Apache的某种插件),该javascript可以找到图像中的颜色并将其替换为自定义调色板中最接近的颜色,在我的情况下为 NES调色板.该怎么办?

What I need is a javascript (or perhaps some kind of a plugin using PHP/Apache) that can find the colors in an image and replace them with the closest color from a custom palette, in my case the NES palette. How can this be done?

推荐答案

是的,可以按照以下步骤使用javascript来完成:

Yes, it can be done using javascript, by following these steps :

  1. 将图像加载到画布中
  2. 获取图像数据(每个像素的rgba值数组)
  3. 循环遍历数组并将rgba值转换为十六进制值
  4. 将结果颜色转换为调色板中最接近的颜色
  5. 将新颜色转换回rgba值
  6. 将新的imagedata数组恢复到画布上

这篇关于可以使用javascript更改图像调色板吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆