0

画像を取得してドロップ シャドウを適用し、画像として保存しようとしています。

これまでのところ、サードパーティのソリューションを使用せずにこれを行う唯一の方法は、 で を使用することDropShadowEffectですDrawingVisual

var drawingVisual = new DrawingVisual();
drawingVisual.Effect = new DropShadowEffect
{
    Color = Color.FromArgb(255, 0, 0, 0),
    BlurRadius = 5,
    Opacity = 1,
    Direction = 45,
    ShadowDepth = 6
};

using (var drawingContext = drawingVisual.RenderOpen())
{
    var left = 0; //??
    var top = 0; //??
    var totalWidth = left + image.Width; //??
    var totalHeight = top + image.Height; //??

    //Background.
    drawingContext.DrawRectangle(new SolidColorBrush(Colors.White), null, new Rect(0,0, totalWidth, totalHeight));

    //Image.
    drawingContext.DrawImage(image, new Rect(left, top, image.Width, image.Height));
}

var frameHeight = image.PixelHeight; //??
var frameWidth = image.PixelWidth; //??

//Converts the Visual (DrawingVisual) into a BitmapSource.
var bmp = new RenderTargetBitmap(frameWidth, frameHeight, imageDpi, imageDpi, PixelFormats.Pbgra32);
bmp.Render(drawingVisual);

//Creates a PngBitmapEncoder and adds the BitmapSource to the frames of the encoder.
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmp));

//Saves the image into a file using the encoder.
using (Stream stream = File.Create(frame.Path))
    encoder.Save(stream);

特定のDropShadowEffect.

それを測定する組み込みの方法はありますか、それとも手動で行う必要がありますか? どのように手動で行うことができますか?

4

1 に答える 1