如何创建简单的玻璃效果

发布于 2024-09-08 20:12:05 字数 309 浏览 5 评论 0原文

我目前正在自己​​绘制的对象上绘制浅蓝色、部分透明的覆盖层以指示某种状态。没关系,但我认为如果我能以某种玻璃效果来进一步确立特定物体上面覆盖有“东西”的想法,那就更好了。

例如,我认为除了蓝色透明度之外,一些玻璃条纹也会产生很好的效果。

我在 Google 上搜索过 GDI+(和其他)算法来完成像这样的简单绘画,但一无所获。任何语言的任何(相当简单)算法的链接将不胜感激。我更喜欢 .NET,但可以从伪代码中找出绘画。

抱歉,还应该指定我需要以 WinXP 为目标并使用 .NET 版本 2.0 - 因此无法使用 WPF 或 Vista/Win7 功能。

I am currently painting a light blue, partly transparent overlay over owner-drawn objects to indicate certain state. It's OK but I thought that it would be even nicer if I could at some sort of glass effect to further establish the idea that the particular object has "something" overlaid over the top of it.

I thought that some glass streaks, for example, in addition to the blue transparency would lend a nice effect.

I've Googled around for GDI+ (and others) algorithms to do simple things painting like this but have come up empty. Links to any (fairly simple) algorithms in any language would be appreciated. I prefer .NET but can figure out the painting from pseudo-code on up.

Sorry, shoul've also specified that I need to target WinXP and using .NET version 2.0 - So unable to use WPF or Vista/Win7 goodies.

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

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

发布评论

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

评论(3

做个ˇ局外人 2024-09-15 20:12:05

我自己没有这样做,但是使用了 codeproject 源来渲染示例...尝试一下:

http://www.codeproject.com/KB/GDI-plus/Image-Glass-Reflection.aspx

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;
}

I've not done this myself but, have used codeproject source to render a sample...Try this:

http://www.codeproject.com/KB/GDI-plus/Image-Glass-Reflection.aspx

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;
}
柠檬 2024-09-15 20:12:05

实际上,我通过在图像上覆盖一个大小约为下图三分之一的矩形来实现基本的玻璃效果,该矩形包含白色渐变填充,从 25% 不透明度开始一直到 75% 不透明度。这一点绘画产生了我很满意的玻璃状“条纹”。可以使用不同的矩形宽度重复相同的想法多次,以产生多个“条纹”,从而产生玻璃覆盖层的错觉。

I was actually able to achieve a basic glass effect by overlaying my image with a rectangle about one third the size of the image below that contains a gradient fill of white that starts at 25% opacity and goes to 75% opacity. This is single bit of painting produces a glassy "streak" that I was happy with. The same idea could be repeated a number of times with a variety of rect widths to produce several "streaks" that will give the illusion of a glass overlay.

倾其所爱 2024-09-15 20:12:05

如果您使用的是 Vista 或 Windows 7,您可以尝试 Aero Glass 功能。

这些可能会有所帮助:

http://msdn.microsoft.com/en-us/library/aa969537%28VS.85%29.aspx#blurbehind
http://msdn.microsoft.com/en-us/library/ms748975。 ASPX

You could try the Aero Glass function, if you are using Vista or Windows 7.

These might be helpful:

http://msdn.microsoft.com/en-us/library/aa969537%28VS.85%29.aspx#blurbehind
http://msdn.microsoft.com/en-us/library/ms748975.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文