问题描述
给定:具有其颜色(表示为PC0)和α值(表示为PA0)的像素,其分布在某种颜色(表示为BC)的背景上。
问题:如何为另一个值(表示为PA1)改变像素(PA0)的Alpha值,以使得像素和背景的合成颜色不变(PBC0 == PBC1)?换句话说,你会如何找到这样的PC1,使得原始的和结果的复合颜色(PBC0和PBC1)看起来相同?
PBC0 = PC0 * PA0 + BC *(1-PA0)
= PC1 * PA1 + BC *(1-PA1)
如果您知道PA0和PA1,您可以解决PC1。
PC1 =(PC0 * PA0 + BC *(1-PA0) - BC *(1-PA1))/ PA1
编辑:如果您使用范围从0-255的颜色值的常见惯例,则在上面的代码中替换为255.
Given: A pixel, with its color (denoted as PC0) and alpha value (denoted as PA0), which is layered over a background of some color (denoted as BC).
Question: How would you change the alpha value of the pixel (PA0) for another value (denoted as PA1) so that the resulting composite color of the pixel and the background does not change (PBC0 == PBC1)? In other words, how would you find such PC1 that makes the original and resulting composite colors (PBC0 and PBC1) look identical?
解决方案PBC0 = PC0*PA0 + BC*(1-PA0) = PC1*PA1 + BC*(1-PA1)
If you know both PA0 and PA1, you can solve for PC1.
PC1 = (PC0*PA0 + BC*(1-PA0) - BC*(1-PA1)) / PA1
Edit: substitute 255 for 1 in the above if you're using the common convention of color values ranging from 0-255.
这篇关于如何更改像素的alpha而不更改生成的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!