WPF - 如何对裁剪后的图像应用效果?
我有一个 Image
被剪裁如下:
<Image Width="45" Grid.Column="0" Source="{Binding Photo}">
<Image.Clip>
<RectangleGeometry Rect="0,0,45,55" RadiusX="8" RadiusY="8" />
</Image.Clip>
</Image>
如何对其应用投影效果?
更新:
正如 Ray 所指出的,最好的解决方案是 Anderson 提出的方案 - 具有环绕边框。谢谢安德森。
I have an Image
being clipped like so:
<Image Width="45" Grid.Column="0" Source="{Binding Photo}">
<Image.Clip>
<RectangleGeometry Rect="0,0,45,55" RadiusX="8" RadiusY="8" />
</Image.Clip>
</Image>
How can I apply a drop shadow effect to it?
UPDATE:
As pointed out by Ray, the best solution is the one proposed by Anderson - having a wrapping border. Thanks Anderson.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这将为您解决问题:
这当然是您最初的想法,只是将 DropShadowEffect 应用于环绕边框。由于位图效果的工作方式,它们仅适用于所包含内容的可见部分。
This will do the trick for you:
Which of course is your original idea, only with the DropShadowEffect applied to a wrapping Border. Because of the way bitmap effects work, they apply only to the visible part of what is contained.
这应该可行,
不过我还没有尝试过与 Clip 结合使用。
更新:这不起作用(似乎是一个错误?)
我只是这样做:
有点蹩脚,你可能需要调整一些宽度以确保它们完全匹配,但你明白了。
This should work
I've not tried it in combination with Clip, though.
Update: That doesn't work (seems like a bug?)
I'd just do this:
Bit lame and you might have to tweak some of the widths to make sure they match exactly, but you get the idea.
我想答案是我需要使用 CroppedBitmap 而不是 Image.Clip:
如果我需要圆角,我可以用边框包围外部图像并使用 ImageBrush:
如果我错了,请纠正我,或者你可以这样做以更简单的方式。
谢谢!
更新:显然您无法绑定到 CroppedBitmap 的 Source 属性!
I guess the answer is that I need to use CroppedBitmap instead of Image.Clip:
and if I need the round corners I can surround the outer image with a border and use a ImageBrush:
Please correct me if I am wrong or you can do it in a simpler manner.
Thanks!
UPDATE: Apparently you cannot bind to CroppedBitmap's Source property!