Fondo Blur GDI+ [Aporte]

Iniciado por Keyen Night, 18 Noviembre 2012, 03:10 AM

0 Miembros y 1 Visitante están viendo este tema.

Keyen Night

El Visual Studio es excelente para el diseño a falta de potencia, entonces si tenemos esta herramienta pues explotemosla :xD

Aquí le dejo un modulo que quizá a alguien le pueda servir, crea un Form cuyo BackGroundImage es un ScreenShot con el efecto Blur se muestra con control de opacidad de una manera muy visual, esto sirve si queremos llamar la atención del usuario a nuestra aplicación más o menos lo que hace el UAC cuando nos da una advertencia pero con Blur, es un código sencillo que puede resaltar el detalle del diseño en cualquier aplicación...

El BlurForce mientras más alto más desenfoca pero tarda más en aplicar el efecto, se recomiendan valores del 1 al 5, por defecto es 2, la función tiene por defecto 1.

Speed define la velocidad para pasar la opacidad del Form de 0 a 1 y viceversa, por defecto es 0.025/1 ms.

Coloque la función Blur a parte para que se pudiese detallar su funcionamiento.

El Sub BlurBitmap proviene de: http://vbdotnetpower.blogspot.com/2011/06/image-effect-bluring.html

Código (vb.net) [Seleccionar]

Module BlurBackground

   Private WithEvents Background As New Form With {.Bounds = SystemInformation.VirtualScreen, _
                                                   .StartPosition = FormStartPosition.Manual, _
                                                   .TopMost = True, _
                                                   .Opacity = 0, _
                                                   .BackgroundImageLayout = ImageLayout.None, _
                                                   .FormBorderStyle = FormBorderStyle.None, _
                                                   .BackgroundImage = Nothing, _
                                                   .ShowIcon = False, _
                                                   .ShowInTaskbar = False}

   Private WithEvents Timer As New Timer With {.Enabled = False, .Interval = 1}

   Public Speed As Double

   Private Sub BlurBitmap(ByRef Image As Bitmap, Optional ByVal BlurForce As Integer = 1)
       Dim _
       Graph As Graphics = Graphics.FromImage(Image), _
       ImgAtt As New ImageAttributes, _
       Matrix As New ColorMatrix
       Matrix.Matrix33 = 0.5F
       ImgAtt.SetColorMatrix(Matrix)
       For x As Integer = -BlurForce To BlurForce
           For y As Integer = -BlurForce To BlurForce
               Graph.DrawImage(Image, New Rectangle(x, y, _
                                                    Image.Width, _
                                                    Image.Height), _
                                                    0, 0, Image.Width, _
                                                    Image.Height, _
                                                    GraphicsUnit.Pixel, ImgAtt)
           Next
       Next
       ImgAtt.Dispose()
       Graph.Dispose()
   End Sub

   Public Sub ShowBackground()

       If Background.BackgroundImage IsNot Nothing Then
           Background.BackgroundImage.Dispose()
       End If

       Dim BlurBack As New Bitmap(SystemInformation.VirtualScreen.Width, _
                                  SystemInformation.VirtualScreen.Height)

       Dim BlurGraph As Graphics = Graphics.FromImage(BlurBack)

       BlurGraph.CopyFromScreen(0, 0, 0, 0, SystemInformation.VirtualScreen.Size)

       BlurBitmap(BlurBack, 2)

       BlurGraph.Dispose()

       Background.BackgroundImage = BlurBack
       If Not Timer.Enabled And Not Background.Visible Then
           Background.Show()
           Speed = 0.025
           Timer.Start()
       End If
   End Sub

   Public Sub HideBackground()
       If Not Timer.Enabled And Background.Visible Then
           Speed = -0.025
           Timer.Start()
       End If
   End Sub

   Private Sub Timer_Tick(ByVal sender As Timer, ByVal e As System.EventArgs) Handles Timer.Tick

       Select Case Background.Opacity + Speed
           Case Is > 1
               Timer.Stop()
               Exit Sub
           Case Is < 0
               Timer.Stop()
               Background.Hide()
       End Select

       Background.Opacity += Speed

   End Sub

   'Solo por seguridad para cerrar el Form con un click'
   Private Sub Background_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Background.Click
       HideBackground()
   End Sub

End Module

La Fé Mueve Montañas...
                                    ...De Dinero

La programación es más que un trabajo es más que un hobby es una pasión...