1. Este site usa cookies. Ao continuar a usar este site está a concordar com o nosso uso de cookies. Saber Mais.

[VB2010] - nao consigo combinar os pixels:(

Discussão em 'Programação' iniciada por Cambalinho, 14 de Janeiro de 2013. (Respostas: 0; Visualizações: 460)

  1. Cambalinho

    Cambalinho Power Member

    tenho 1 funçao que deveria combinar os pixels da srcBmp para a srcBmp1. mas algo esta errado no codigo e não sei o que é:(
    Código:
    lngdstColor = srcBmp1.GetPixel(x, y)
                    lngsrcColor = srcBmp.GetPixel(x, y)
                    Debug.Print(lngdstColor.ToString)
    parece me dar '0':(
    Código:
    Public Function TransparentAlphaBlend(ByVal Source As Control, ByVal Destination As Control, ByVal Opacy As Long, ByVal TransparentColor As Color) As Bitmap
            Dim x As Integer, y As Integer
    
            'Get a Graphics Object from the form
            Dim srcPic As Graphics = Source.CreateGraphics
            'Create a EMPTY bitmap from that graphics
            Dim srcBmp As New Bitmap(Source.Width, Source.Height, srcPic)
    
            'Get a Graphics Object from the form
            Dim srcPic1 As Graphics = Destination.CreateGraphics
            'Create a EMPTY bitmap from that graphics
            Dim srcBmp1 As New Bitmap(Destination.Width, Destination.Height, srcPic1)
    
            Dim r As Integer
            Dim g As Integer
            Dim b As Integer
    
            Dim lngsrcColor As Color
            Dim lngdstColor As Color
            Dim lngNewColor As Color
    
            Dim dblAlpha As Double
    
    
    
            'convert the values from 0-100 to 0-255
            dblAlpha = 255 - (Opacy * 255 / 100)
    
    
    
            For x = 0 To Destination.Width - 1
                For y = 0 To Destination.Height - 1
                    'geting the source and destination colors\pixels
                    lngdstColor = srcBmp1.GetPixel(x, y)
                    lngsrcColor = srcBmp.GetPixel(x, y)
                    Debug.Print(lngdstColor.ToString)
                    'if source pixel is tranparentcolor then ignore it
                    If lngsrcColor <> TransparentColor Then
    
    
                        'FinalPixel = (AlphaValue * (Source + 256 - Destination)) / 256 + Destination - AlphaValue
                        'now i must combine them with alpha values for make the opacy\fade
                        r = (dblAlpha * (lngsrcColor.R + 256 - lngdstColor.R)) / 256 + lngdstColor.R - dblAlpha
                        g = (dblAlpha * (lngsrcColor.G + 256 - lngdstColor.G)) / 256 + lngdstColor.G - dblAlpha
                        b = (dblAlpha * (lngsrcColor.B + 256 - lngdstColor.B)) / 256 + lngdstColor.B - dblAlpha
    
                        lngNewColor = Color.FromArgb(RGB(r, g, b))
    
                        'now that i have the new color, i use it
                        srcBmp1.SetPixel(x, y, lngNewColor)
                    Else
                        srcBmp1.SetPixel(x, y, TransparentColor)
                    End If
                Next y
            Next x
            
            TransparentAlphaBlend = srcBmp1.Clone()
            srcPic.Dispose()
            srcPic1.Dispose()
        End Function
    alguem me pode dizer onde errei?
    (se for preciso alguma explicaçao do codigo, basta pedir;))
     

Partilhar esta Página