Page 1 of 1

Merging .dds (greyscale) Alpha / Transparency

Posted: 2018-12-06T10:16:25-07:00
by Maci
I'm currently trying to merge .dds files using Magick.NET, however, I can't seem to figure out how to make it respect the Alpha channel too.
I get good results on the RGB channels using either the Merge or Mosaic functions, but both give me a completely white Alpha channel.

Here's what I have:

Code: Select all

            using (MagickImageCollection images = new MagickImageCollection())
            {
                MagickImage first = new MagickImage(@"C:\Users\a\Desktop\test\1.dds");
                images.Add(first);

                MagickImage second = new MagickImage(@"C:\Users\a\Desktop\test\2.dds");
                images.Add(second);

                using (IMagickImage result = images.Merge())
                {
                    result.Settings.SetDefine(MagickFormat.Dds, "compression", "dxt5");
                    result.Write(@"C:\Users\a\Desktop\test\result.dds");
                }
            }
It's basically just one of the examples adjusted.
I've tried playing arround with defines, AlphaOptions and have been trying to solve this for a couple of hours with no luck.
Any ideas?

Re: Merging .dds (greyscale) Alpha / Transparency

Posted: 2018-12-06T10:22:06-07:00
by snibgo
I suppose "images.Merge())" does the same as CLI "-layers merge". See http://www.imagemagick.org/script/comma ... php#layers . This flattens images against the background colour, which defaults to opaque white. Is this what happens for you? You can make the background "None", which is transparent black, if you want.

Re: Merging .dds (greyscale) Alpha / Transparency

Posted: 2018-12-06T10:36:19-07:00
by Maci
snibgo wrote: 2018-12-06T10:22:06-07:00 I suppose "images.Merge())" does the same as CLI "-layers merge". See http://www.imagemagick.org/script/comma ... php#layers . This flattens images against the background colour, which defaults to opaque white. Is this what happens for you? You can make the background "None", which is transparent black, if you want.
Ah yes, adding

first.BackgroundColor = new MagickColor(0, 0, 0, 0);
and
second.BackgroundColor = new MagickColor(0, 0, 0, 0);

before the Merge makes it work perfectly, thanks!
Any way to just set a universal BackgroundColor?

Re: Merging .dds (greyscale) Alpha / Transparency

Posted: 2018-12-06T11:13:33-07:00
by snibgo
At the command line, "-background None" will set it for all following operations. I don't use Magick.NET, but I don't think it works in the same way, so you need to set it for each individual image.