伪透明图像

发布于 2024-08-31 09:29:37 字数 292 浏览 4 评论 0原文

对于大学作业,我们使用一种相当陌生的语言 Modula 2 进行编程,该语言缺乏主要的图形支持。

我想知道如何在图像上实现“透明”效果,我想它会像这样工作:

为图像的背景区域创建一个二维数组,填充该区域中不同像素的颜色,创建另一个二维数组图像再次具有每张图片的颜色,然后合并像素颜色并在适当的位置绘制不同的“新颜色”。

我想知道的是:如何合并颜色(十六进制)

( colour1 + colour2 ) / 2 

:?

感谢您的帮助!!

For an assignment at university we program in a pretty unknown language Modula 2, which lacks major graphic support.

I was wondering how to achieve a 'transparency' effect on images, i figured it would work like this:

Create a 2D array for the background area of the image filled with the colours of the different pixels in that area, create another 2D array of the image with again the colours of every picture and than merge the pixel colours and draw the different "new colours" on their appropriate place.

What i was wondering about: how do i merge the colours (hexadecimals) just:

( colour1 + colour2 ) / 2 

?

Thanks for your help!!

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

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

发布评论

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

评论(1

等风来 2024-09-07 09:29:37

不,你不会对数字进行平均。
假设它们以这种形式存储:

RRGGBB

那么由于颜色分量之间的溢出,平均会导致奇怪的事情发生。您想要做的是对每个单独的分量(即红色、绿色和蓝色)进行平均,然后将它们组合在一起。在伪代码中(抱歉我实际上不知道 modula-2):

for each pixel:
    color1 := <original background color>
    color2 := <new color>
    resultred := (color1.redpart + color2.redpart) / 2
    resultgreen := (color1.greenpart + color2.greenpart) / 2
    resultblue := (color1.bluepart + color2.bluepart) / 2
    result := combineRGB(resultred,resultgreen,resultblue)
    draw result onto pixel

No, you would not average the numbers.
Assuming they are stored in this form:

RRGGBB

then averaging would make weird things happen because of the spillover between color components. What you want to do is average each individual component (i.e. red, green, and blue) and then combine them together. In pseudocode (sorry i don't actually know modula-2):

for each pixel:
    color1 := <original background color>
    color2 := <new color>
    resultred := (color1.redpart + color2.redpart) / 2
    resultgreen := (color1.greenpart + color2.greenpart) / 2
    resultblue := (color1.bluepart + color2.bluepart) / 2
    result := combineRGB(resultred,resultgreen,resultblue)
    draw result onto pixel
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文