Magick.net C# 的 ImageMagick 命令行

ImageMagick Command line to Magick.net C#

嘿,我有以下命令行,非常适合我想做的事情,但无法将其运行转换为 C# Magick.net 版本:

convert YnTf9.png ^
( -clone 0 -blur 0x5 -gravity center -crop 400x300+0+0 +repage ) ^
( -clone 0 -resize x300 ) ^
-delete 0 ^
-gravity center -compose over -composite ^
result.png

到目前为止我有这个 c# 代码:

using (MagickImage image = new MagickImage(@"C:\Users\David\Pictures\YnTf9.png"))
{
     using (MagickImage backgroundImg = (MagickImage)image.Clone())
     {
          backgroundImg.Blur(0, 5);
          backgroundImg.Crop(400, 300, Gravity.Center);
          backgroundImg.RePage();
          backgroundImg.Resize(0, 300);

          image.Composite(backgroundImg, Gravity.Center, CompositeOperator.SrcOver);
          image.Write("CODETest.png");
     }
}

之后我 运行 它和正常图像一样出来了:

什么时候应该是这样的:

所以我知道我没有按照正确的顺序执行 ether and/or 正确的命令。

如果有人能帮我运行写就太好了! :)

括号之间的-clone创建一个单独的图像:

convert YnTf9.png ^
# Creates a copy of YnTf9.png.
( -clone 0 -blur 0x5 -gravity center -crop 400x300+0+0 +repage ) ^
# Creates another copy of YnTf9.png
( -clone 0 -resize x300 ) ^
# Removes YnTf9.png from the image list, you now only have the two clones
-delete 0 ^
-gravity center -compose over -composite ^
result.png

但在您的情况下,您不需要创建第二个克隆。您的命令可以翻译成这样:

using (MagickImage image = new MagickImage("i:/YnTf9.png"))
{
    using (IMagickImage backgroundImg = image.Clone())
    {
        backgroundImg.Blur(0, 5);
        backgroundImg.Crop(400, 300, Gravity.Center);
        backgroundImg.RePage();

        // Resize the original image instead of creating a clone, resizing it and then
        // delete the original.
        image.Resize(0, 300);

        backgroundImg.Composite(image, Gravity.Center, CompositeOperator.SrcOver);
        backgroundImg.Write("i:/result.png");
    }
 }

知道了

using (MagickImage image = new MagickImage(bitmap))
    {
        using (IMagickImage backgroundImg = image.Clone())
        {
            backgroundImg.Blur(0, 5);
            backgroundImg.Crop(400, 300, Gravity.Center);
            backgroundImg.RePage();

            image.Resize(0, 300);

            IMagickImage _shadow = new MagickImage(MagickColor.FromRgb(0, 0, 0), image.Width + 20, 400);
_shadow.Shadow(backgroundImg.Width, 400, 10, (Percentage)90);

            backgroundImg.Composite(_shadow, Gravity.Center, CompositeOperator.Atop);
            backgroundImg.Composite(image, Gravity.Center, CompositeOperator.SrcAtop);
            backgroundImg.Write(@"C:\Users\David\Pictures\NEWest.png");
        }
    }