C# 如何创建简单的玻璃效果
我目前正在绘制一个浅蓝色、部分透明的覆盖层,覆盖在所有者绘制的对象上,以指示特定的状态。这没关系,但我认为如果我能在某种玻璃效果上进一步建立这样一种想法,那就更好了,即特定物体的顶部覆盖着“某物” 例如,我认为除了蓝色透明外,一些玻璃条纹会产生很好的效果 我在谷歌上搜索过GDI+(和其他)算法来完成像这样简单的绘画,但结果却是空的。任何语言的任何(相当简单)算法的链接将不胜感激。我更喜欢.NET,但我可以从伪代码中找到这幅画C# 如何创建简单的玻璃效果,c#,vb.net,language-agnostic,gdi+,paint,C#,Vb.net,Language Agnostic,Gdi+,Paint,我目前正在绘制一个浅蓝色、部分透明的覆盖层,覆盖在所有者绘制的对象上,以指示特定的状态。这没关系,但我认为如果我能在某种玻璃效果上进一步建立这样一种想法,那就更好了,即特定物体的顶部覆盖着“某物” 例如,我认为除了蓝色透明外,一些玻璃条纹会产生很好的效果 我在谷歌上搜索过GDI+(和其他)算法来完成像这样简单的绘画,但结果却是空的。任何语言的任何(相当简单)算法的链接将不胜感激。我更喜欢.NET,但我可以从伪代码中找到这幅画 抱歉,我还应该指定我需要以WinXP为目标并使用.NET 2.0版-因
抱歉,我还应该指定我需要以WinXP为目标并使用.NET 2.0版-因此无法使用WPF或Vista/Win7。如果您使用的是Vista或Windows 7,您可以尝试Aero Glass功能 这些可能会有所帮助:
我自己并没有这样做,但我已经使用codeproject source渲染了一个示例…请尝试以下操作:
实际上,我可以通过在我的图像上叠加一个矩形来实现基本的玻璃效果,这个矩形的大小大约是下面图像的三分之一,包含一个白色渐变填充,从25%不透明度开始,到75%不透明度。这是一幅我很满意的玻璃般的“条纹”。同样的想法可以用不同的矩形宽度重复多次,以产生几个“条纹”,从而产生玻璃覆盖层的错觉。wpf是你的解决方案=p wpf会很棒,但我被困在.NET 2.0中。所以你错过了LINQ&stuff????可怜的悲伤灵魂=(这需要每个控件都有一个单独的窗口,你需要用底层的形式移动它…实际上听起来不太好。不完全是:“应用程序可以在窗口的整个客户端区域或特定子区域后应用模糊效果。这使应用程序能够添加样式化的路径和搜索栏,这些路径和搜索栏在视觉上与应用程序的其余部分分开。”
public static Image DrawReflection(Image _Image, Color _BackgroundColor, int _Reflectivity)
{
// Calculate the size of the new image
int height = (int)(_Image.Height + (_Image.Height * ((float)_Reflectivity / 255)));
Bitmap newImage = new Bitmap(_Image.Width, height, PixelFormat.Format24bppRgb);
newImage.SetResolution(_Image.HorizontalResolution, _Image.VerticalResolution);
using (Graphics graphics = Graphics.FromImage(newImage))
{
// Initialize main graphics buffer
graphics.Clear(_BackgroundColor);
graphics.DrawImage(_Image, new Point(0, 0));
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
Rectangle destinationRectangle = new Rectangle(0, _Image.Size.Height,
_Image.Size.Width, _Image.Size.Height);
// Prepare the reflected image
int reflectionHeight = (_Image.Height * _Reflectivity) / 255;
Image reflectedImage = new Bitmap(_Image.Width, reflectionHeight);
// Draw just the reflection on a second graphics buffer
using (Graphics gReflection = Graphics.FromImage(reflectedImage))
{
gReflection.DrawImage(_Image,
new Rectangle(0, 0, reflectedImage.Width, reflectedImage.Height),
0, _Image.Height - reflectedImage.Height, reflectedImage.Width,
reflectedImage.Height, GraphicsUnit.Pixel);
}
reflectedImage.RotateFlip(RotateFlipType.RotateNoneFlipY);
Rectangle imageRectangle =
new Rectangle(destinationRectangle.X, destinationRectangle.Y,
destinationRectangle.Width,
(destinationRectangle.Height * _Reflectivity) / 255);
// Draw the image on the original graphics
graphics.DrawImage(reflectedImage, imageRectangle);
// Finish the reflection using a gradiend brush
LinearGradientBrush brush = new LinearGradientBrush(imageRectangle,
Color.FromArgb(255 - _Reflectivity, _BackgroundColor),
_BackgroundColor, 90, false);
graphics.FillRectangle(brush, imageRectangle);
}
return newImage;
}