本文介绍了更改Html5画布元素的颜色深度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有一种方法可以改变HTML5画布元素中的图像的颜色深度,即图像中每个像素的颜色将以更小的颜色位深度舍入为最接近的等价物, 例如。谢谢。
I was wondering if there was a way to alter the color depth of the image in an HTML5 Canvas Element, in that the color of each pixel in the image will get "rounded" to the nearest equivalent in a lesser color bit depth, for instance. Thank you.
推荐答案
是的,可以做,也不难。在这里查看我的回答:如何使用渐变贴图来调整HTML5画布与画布中的图片。
着色,所有你必须做的是遍历每个像素,更改RGB值更小(步骤8或16而不是步骤1)
redValue = redValue - (redValue % 32) // 155 would become 128, etc
Which ought to work, but you should check the edge cases.
这篇关于更改Html5画布元素的颜色深度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!