开发者

Pseudo Transparent images

开发者 https://www.devze.com 2022-12-29 06:02 出处:网络
For an assignment at university we program in a pretty unknown language Modula 2, which lacks major graphic support.

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 diff开发者_StackOverflowerent "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!!


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号