Quantcast
Channel: WriteableBitmapEx
Viewing all articles
Browse latest Browse all 360

New Post: No alpha blending in the FillXXX methods

$
0
0
For VB.net, with modification:
   Public Shared Sub FillRectangle2(ByRef bmp As WriteableBitmap, x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer, color As Color)
        ' Use refs for faster access (really important!) speeds up a lot!
        Dim w As Integer = bmp.PixelWidth
        Dim h As Integer = bmp.PixelHeight
        Dim pixels As Integer() = bmp.Pixels

        ' Check boundaries
        If x1 < 0 Then
            x1 = 0
        End If
        If y1 < 0 Then
            y1 = 0
        End If
        If x2 < 0 Then
            x2 = 0
        End If
        If y2 < 0 Then
            y2 = 0
        End If
        If x1 >= w Then
            x1 = w - 1
        End If
        If y1 >= h Then
            y1 = h - 1
        End If
        If x2 >= w Then
            x2 = w - 1
        End If
        If y2 >= h Then
            y2 = h - 1
        End If

        For y As Integer = y1 To y2
            For i As Integer = y * w + x1 To y * w + x2
                Dim oneOverAlpha As Byte = CByte(255 - color.A)
                Dim c As Integer = pixels(i)

                Dim r As Integer = ((((c >> 16) And 255) * oneOverAlpha) + (color.R * color.A)) >> 8
                Dim g As Integer = ((((c >> 8) And 255) * oneOverAlpha) + (color.G * color.A)) >> 8
                Dim b As Integer = ((((c >> 0) And 255) * oneOverAlpha) + (color.B * color.A)) >> 8

                pixels(i) = 255 << 24 Or r << 16 Or g << 8 Or b
            Next
        Next

    End Sub

Viewing all articles
Browse latest Browse all 360

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>