This project has moved and is read-only. For the latest updates, please go here.

How to write Background?

Dec 30, 2016 at 1:30 PM
Hello. I'm beginner.
I have a problem.
I want to do this ImageMagick command with Magick.NET.
convert hoge.psd -set dispose Background -coalesce -delete 0 fuga_%04d.png
This command is written here "psdをレイヤー別にpngで保存する方法"
this Japanese mean "way of convert psd file to png".

How to write this command "Background" with Magick.NET?

I wrote this code.
using ImageMagick;

namespace psd
{
    class Program
    {
        static void Main(string[] args)
        {
            ImageMagick.MagickReadSettings settings =
                   new ImageMagick.MagickReadSettings();

            settings.BackgroundColor = new MagickColor(0, 0, 0, 0);

            MagickImageCollection imgs =
                new ImageMagick.MagickImageCollection("psdfile.psd", settings);

            imgs.Coalesce();
            imgs.RemoveAt(0);

            imgs.Write("pngfile%04d.png");

            imgs.Dispose();
        }
    }
}
This code can't make the background completely transparent.
Thanks for reading to the end.
Dec 30, 2016 at 4:17 PM
The command -set dispose Background will set the gif dispose method to background dispose. You will need to do this instead:
using ImageMagick;

namespace psd
{
    class Program
    {
        static void Main(string[] args)
        {
            using (MagickImageCollection imgs = new MagickImageCollection("psdfile.psd"))
            {
                foreach (MagickImage img in imgs)
                {
                    img.GifDisposeMethod = GifDisposeMethod.Background;
                }

                imgs.Coalesce();
                imgs.RemoveAt(0);

                imgs.Write("pngfile%04d.png");
            }
        }
    }
}
Dec 30, 2016 at 4:52 PM
Thank you very much\(≧▽≦)ノ
I could do something I wanted to do.
Thank you for your help.