|Version 4.42 of MUSHclient introduces a new script function WindowDrawImageAlpha. This behaves in a similar way to WindowDrawImage however it lets you draw a PNG image which has an imbedded alpha channel, and respects the alpha information in such an image.|
The images in the next posting show the general idea. What this lets you do is have images with soft edges. Previously an image had to be rectangular, with a possible single transparent colour through which you could see the underlying image. Now you can make an alpha channel (with a suitable painting program) which lets you gradually blend into the background.
An example of doing this is here:
win = GetPluginID () -- get a unique name
WindowCreate (win, 0, 0, 365, 285, 12, 0, ColourNameToRGB("white")) -- create window
for i = 1, math.max (WindowInfo (win, 3), WindowInfo (win, 4)) / 20 do
WindowLine (win, i * 20, 0, i * 20, WindowInfo (win, 4), 0xC0C0C0, 0, 1)
WindowLine (win, 0, i * 20, WindowInfo (win, 3), i * 20, 0xC0C0C0, 0, 1)
end -- for
check (WindowLoadImage (win, "im", "C:/alpha_test.png"))
check (WindowDrawImageAlpha (win, "im", 20, 20, 0, 0, 1) )
WindowShow (win, true) -- show it
Previously you could do something similar with WindowMergeImageAlpha - however this required two images, which was a bit fiddly to set up, whereas this new function just lets you use a single existing image with an alpha channel.
The alpha channel effectively is a 4th byte per pixel (the others being the red, green and blue components of the pixel). This 4th byte specifies the transparency of the pixel, from fully transparent (0) to fully opaque (255), in the range 0 to 255. As you can see from the mask in the image below the black parts (which have a value of 0) are transparent, so the background shows through. The white parts (which have a value of 255) are opaque, so you do not see the background. The grey parts (somewhere between 1 and 254) let the background image show through partially.
This will only work for PNG images which have an alpha channel imbedded in them.
- Nick Gammon
| top |