WPF创建自定义位图效果 [英] WPF create custom bitmap effect

查看:148
本文介绍了WPF创建自定义位图效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下一个问题。

我如何制作自定义位图效果,将它们应用到网格的背景中。

我有一个窗口。它上面有一个背景图片。我有一个用户控件,其中包含窗口的背景图像必须具有效果的网格,例如灰度。我怎么能这样做?

PS。请不要写lol。尝试谷歌azazaz或其他拖钓答案。

Hi, i have next question.
How i can make custom bitmap effect to apply them to grid's background.
I have a window. There is a background image on it. And i have a user-control, that contains grid where background image of window must have an effect, for example, grayscale. How i can do this?
PS. please, do not write something like "lol. try to google it azazaz" or another trolling answers.

推荐答案

您可以从MSDN查看资源是否有关于此类主题的数据。他们已经有了这些主题的实例,这些主题很有帮助,并且(在他们正在执行的几乎每一行代码中都有注释)解释代码及其在上下文中的用法。



这是代码将图像转换为GreyScale [ ^ ]。



您可以从已存在的图像或运行时创建位图图像。



You can look into resources are data on such topics from MSDN. They've got working example on these topics that are helpfull and have comments (on almost each and every line of code they're executing) that explain the code and its usage in the context.

Here is the code that converts the Image to GreyScale[^].

You create a Bitmap image from an already present Image or on the runtime.

BitmapImage myBitmapImage = new BitmapImage();





您可以为其添加源。你创建一个FormatChangedBitmap对象





You add a source to it. You create a FormatChangedBitmap object as

FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();





将其源代码添加为UI中的Bitmap。然后,您只需更改像素的格式,并将其更改为GrayScale。在上面的文档中,这一行就是这样做的。





Add its source to be the Bitmap you're having from the UI. Then you just change the format of the pixels, and change them to GrayScale. In the above document, this line does it.

newFormatedBitmapSource.DestinationFormat = PixelFormats.Gray32Float;





完成此操作后,您将创建一个新图像,将其源作为此灰度图像添加,然后在UI中显示。像这样,





Once this is done, you create a new Image, add its source as this grayscale-ed image and then show it inside the UI. Like this,

myImage.Source = newFormatedBitmapSource;





现在将其添加到面板(或面板的背景)。



Now add it to a panel (or the panel's background).


这篇关于WPF创建自定义位图效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆