2010-07-12 65 views
0

我目前在所有者繪製的對象上繪製淺藍色,部分透明的疊加層以指示某些狀態。沒關係,但我認爲如果我能夠通過某種玻璃效應來進一步確定特定對象具有覆蓋其頂部的「某種東西」的想法,它會更好。如何創建簡單的玻璃效果

我認爲一些玻璃條紋,例如,除了藍色透明度會帶來很好的效果。

我已經搜索了GDI +(和其他)算法來做這樣簡單的事情,但是已經空了。任何語言的任何(相當簡單)算法的鏈接將不勝感激。我更喜歡.NET,但可以從僞代碼中找出繪畫。

對不起,我還指定了我需要針對WinXP並使用.NET 2.0版 - 所以無法使用WPF或Vista/Win7的好東西。

+0

wpf是你的解決方案= P http://journalsill.hjtcentral.com/Home/tabid/428/EntryId/403/Glass-Behavior-for-WPF.aspx – Luiscencio 2010-07-12 22:01:00

+0

WPF會很棒,但我卡在.NET 2.0。 – 2010-07-12 22:12:16

+0

所以你缺少LINQ&東西?可憐的靈魂=( – Luiscencio 2010-07-12 22:20:22

回答

1

我實際上可以通過將我的圖像覆蓋一個矩形大約三分之一的圖像大小,其中包含白色的漸變填充,開始於25%的不透明度和75%的不透明度。這是一點點的繪畫產生了我很滿意的玻璃狀「條紋」。同樣的想法可以用多種矩形重複多次以產生幾個「條紋」,這會給出玻璃覆蓋層的錯覺。

0

你可以嘗試的Aero Glass功能,如果使用的是Vista或Windows 7

這些可能會有所幫助:

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

+0

這將需要一個單獨的窗口爲每個控制,你需要移動它與底層窗體......聽起來不是很好,實際上。 – Joey 2010-07-12 22:06:35

+0

不完全是:「應用程序可以應用模糊效果窗口的整個客戶區域或特定的子區域,這使得應用程序可以添加樣式化的路徑和搜索條,這些條與視覺上與應用程序的其餘部分是分開的。「 – 2010-07-12 22:24:54

1

我沒有這個做自己,但,已使用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; 
}