Set alpha layer (transparency) based on image contents

Ideas for improvements and requests for new features in XnView Classic

Moderators: XnTriq, xnview

Post Reply
robijn
Posts: 9
Joined: Sun Sep 09, 2007 9:04 pm
Location: Netherlands

Set alpha layer (transparency) based on image contents

Post by robijn »

This topic has come up here before, but there has never been a simple suggestion nor implementation.

For 256 color there is the option to choose the transparent index when saving, works for GIF and PNG. But for 24-bit + alpha (together-32 bit), there is no option for changing the transparency (v2.49.3). There is however, the option to view the alpha layer.

I would suggest as a simplest implementation to add a menu entry Edit -> Set alpha layer based on image... , just below Edit -> Background color... that initially can only do the following. It pops up a dialog, in which a 24-bit color value can be chosen. When you press OK, the alpha layer will become 0 where this color is found, and 255 elsewhere. Effectively this means that the selected color has become transparent.

This is enough for many manipulations on generated pictures (which have known exact colors). It also allows changing the transparent color for images already transparent, by first setting the background color correctly (if needed), then making the image 24-bit, then changing back to 32-bit and then setting the alpha layer based on the image. The most important thing: it's relatively simple and risk-less, but makes a lot possible.

If this works satisfactory, later the dialog could be extended to allow working with photos, where you need a range of colors to be transparent. A certain percentage deviation of the brightness, hue and saturation should be allowed to be still transparent. A smoothness value could also generate alpha values in between 0 and 255, to support smooth edges. A color picker would also be an nice option.
Post Reply