Merging .dds (greyscale) Alpha / Transparency

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
Maci
Posts: 2
Joined: 2018-12-06T10:06:23-07:00
Authentication code: 1152

Merging .dds (greyscale) Alpha / Transparency

Post by Maci » 2018-12-06T10:16:25-07:00

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?

snibgo
Posts: 10934
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Merging .dds (greyscale) Alpha / Transparency

Post by snibgo » 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.
snibgo's IM pages: im.snibgo.com

Maci
Posts: 2
Joined: 2018-12-06T10:06:23-07:00
Authentication code: 1152

Re: Merging .dds (greyscale) Alpha / Transparency

Post by Maci » 2018-12-06T10:36:19-07:00

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?

snibgo
Posts: 10934
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Merging .dds (greyscale) Alpha / Transparency

Post by snibgo » 2018-12-06T11:13:33-07:00

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.
snibgo's IM pages: im.snibgo.com

Post Reply