由2个重叠像素组成

由2个重叠像素组成

本文介绍了像素的RGB值,由2个重叠像素组成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个带水和土地的GIF动画。陆地部分有海岸,因此在某些情况下水会覆盖这些海岸。但是,我希望海水在水下稍微可见。基本上,想象一个透明的png代表水,而另一个代表有沙子。合并的2个图像可以看作是第三个图像。

I am creating an animated gif with Water and Land. The Land part has shores, so the water will in some cases be overlaying those shores. However, I wish the shores to still be slightly visible underneath the water. Basically, imagine 1 transparent png which represents water, over another that has sand. The 2 images combined can be viewed as a third image.

我的问题是 - 我如何计算新像素的RGB值,基于顶部的RGBA(具有透明度)和底部的RGB值,以模仿自然的外观。

My question is - how would I calculate the RGB value of the new pixels, based on the top ones RGBA (with transparency) and the bottom ones RGB values, to mimic a natural look.

我将自己更改透明度级别以查看最适合我的内容,但我遗漏了一个公式。

I will change the transparency level myself to see what suits me best, but I'm missing a formula.

编辑:
atm我有一个想法 - 取水的透明度水平的百分比,并根据该百分比计算一个新的RGB。对沙子像素执行相同操作,但使用剩余百分比(100-透明度%)

atm I do have 1 idea - take the percentage of the transparency level of the water, and based on that percentage calculate a new RGB. Do the same for the sand pixels, but with the "remaining" percentage (100-transparency%)

ie(为简单起见,部分为%)
(R1,G1,B1,40)(R2,G2,B2)=第一组的40%+第二组的60%

ie (A part is in %, for simplicity)(R1,G1,B1, 40) (R2,G2,B2) = 40% of first group + 60% of second

推荐答案

Alpha混合要么死了简单(alpha是0-255,所以颜色是目标*(255 - a)+覆盖* a,全部超过255)或非常微妙,当你允许目标也有alpha 。此外,有必要为许多应用程序有效地实现,这通过预乘,然后使用

Alpha blending is either dead simple (alpha is on 0-255, so the colour is destination * (255 - a) + overlay * a, all over 255) or quite subtle, when you allow the destination to also have alpha. Also it is necessary to implement efficiently for many applications, which is done by pre-multiplying, then hardcoding the division by 255 using

 ((x+1) * 257) >> 16;

这篇关于像素的RGB值,由2个重叠像素组成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 05:55