绘制阴影

发布于 2024-07-29 19:34:50 字数 88 浏览 3 评论 0原文

我想向图像文件添加阴影。 最好的方法是什么? 我想过创建一个WPF图像控件并添加位图效果。但是如何将结果保存到文件中?

谢谢,埃里克

I want to add a drop shadow to an image file. What's the best way to do that?
I thought about creating a WPF Image control and adding a bitmap effect.. But how can I save the result to a file?

Thanks, Eric

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掀纱窥君容 2024-08-05 19:34:50

您可以使用 RenderTargetBitmap 和编码器来执行此操作。 编码器可以是 Png、Jpeg 等。
下面的代码 imgControl 代表您的图像控件。 但由于它是位图效果,您可能需要将此图像放入网格内,并给予相当于 dropshadow 的适当边距,然后在下面的代码中使用网格而不是 imgControl。

double Height = imgControl.ActualHeight;
double Width = imgControl.ActualWidth;

RenderTargetBitmap bmp = new RenderTargetBitmap((int)Width, (int)Height, 
                                                96, 96, PixelFormats.Pbgra32);
bmp.Render(imgControl);

BitmapEncoder encoder = new JpegBitmapEncoder();

encoder.Frames.Add(BitmapFrame.Create(bmp));

using (Stream stream = File.Create("Yourfile.jpeg"))
{
    encoder.Save(stream);
}

You can use RenderTargetBitmap and an Encoder to do this. Encoder can be Png,Jpeg etc..
Below code imgControl represents your Image control. But since it is a bitmap effect you might need to put this Image inside a grid and give proper margin equivalent to the dropshadow and then instead of imgControl use the grid in the below code.

double Height = imgControl.ActualHeight;
double Width = imgControl.ActualWidth;

RenderTargetBitmap bmp = new RenderTargetBitmap((int)Width, (int)Height, 
                                                96, 96, PixelFormats.Pbgra32);
bmp.Render(imgControl);

BitmapEncoder encoder = new JpegBitmapEncoder();

encoder.Frames.Add(BitmapFrame.Create(bmp));

using (Stream stream = File.Create("Yourfile.jpeg"))
{
    encoder.Save(stream);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文