问题
Been trying for awhile now trying to get a shadow using the following code:
using (MagickImage image = new MagickImage(@"C:\Users\David\Pictures\YnTf9.png"))
{
MagickImage _shadow = new MagickImage(bitmap);
using (IMagickImage backgroundImg = image.Clone())
{
backgroundImg.Blur(0, 5);
backgroundImg.Crop(400, 300, Gravity.Center);
backgroundImg.RePage();
image.Resize(0, 300);
_shadow.Resize(0, 300);
_shadow.Shadow(10, 10, 0.8, (Percentage)80, MagickColor.FromRgb(0, 0, 0));
backgroundImg.Composite(_shadow, Gravity.Center, CompositeOperator.SrcOver);
backgroundImg.Composite(image, Gravity.Center, CompositeOperator.SrcAtop);
backgroundImg.Write(@"C:\Users\David\Pictures\NEW.png");
}
}
But the outcome looks like it originally did to begin with:
And what I am looking to accomplish with the code above is:
Anyone able to help me out? :)
UPDATE still does not seem to be working...
回答1:
Try this is ImageMagick 7 on Windows in a cmd window (not a bat file):
magick YnTf9.png ^
( -clone 0 -blur 0x10 -gravity center -crop 400x300+0+0 +repage ) ^
( -clone 0 -resize x300 ) ^
( -clone 1 -fill white -colorize 100 ) ^
( -clone 2 -fill black -colorize 100 ) ^
( -clone 3,4 -gravity center -compose over -composite -blur 0x15 -level 40x100% ) ^
-delete 0,3,4 ^
( -clone 0,2 -gravity center -compose multiply -composite ) ^
-delete 0,2 +swap ^
-gravity center -compose over -composite ^
result.png
回答2:
I do not use .NET, but in command line ImageMagick (unix syntax), you can do the following:
Input:
convert YnTf9.png \
\( -clone 0 -blur 0x10 -gravity center -crop 400x300+0+0 +repage \) \
\( -clone 0 -resize x300 \) \
\( -clone 1 -fill white -colorize 100 \) \
\( -clone 2 -fill black -colorize 100 \) \
\( -clone 3,4 -gravity center -compose over -composite -blur 0x15 -level 40x100% \) \
-delete 0,3,4 \
\( -clone 0,2 -gravity center -compose multiply -composite \) \
-delete 0,2 +swap \
-gravity center -compose over -composite \
result.png
来源:https://stackoverflow.com/questions/49240712/magick-image-creating-shadow-behind-the-image