Pseudo Transparent images
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
精彩评论