嘿所有我有以下命令行,它非常适合我想要做的但无法将其转换为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");
}
}
刚刚做完之后,我就把它运行了,它就像普通的图像一样出现了:
什么时候看起来像这样:
所以我知道我没有用以太正确的顺序和/或正确的命令。
如果有人能为我翻译它会很棒! :)
答案 0 :(得分:2)
括号之间的-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");
}
}
答案 1 :(得分:1)
搞定了
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");
}
}