或者改为:
Protected Shared Function GetHalfToneBrush_() As IntPtr
            If _halfToneBrush.Equals(IntPtr.Zero) Then                Dim bitmap As New bitmap(8, 8, PixelFormat.Format32bppArgb)                Dim white As Color = Color.FromArgb(255, 255, 255, 255)
                Dim black As Color = Color.FromArgb(255, 0, 0, 0)                Dim flag As Boolean = True                ' Alternate black and white pixels across all lines
                Dim x As Integer
                Dim y As Integer                For x = 0 To 8 - 1
                    For y = 0 To 8 - 1
                        Dim tempColor As Color
                        If flag Then
                            tempColor = Color.White
                        Else
                            tempColor = Color.Black
                        End If
                        bitmap.SetPixel(x, y, tempColor)
                    Next
                Next                Dim hBitmap As IntPtr = bitmap.GetHbitmap()                Dim brush As Win32.LOGBRUSH = New Win32.LOGBRUSH
                brush.lbStyle = Convert.ToUInt32(Win32.BrushStyles.BS_PATTERN)
                brush.lbHatch = Convert.ToUInt32(hBitmap)
            End If            Return _halfToneBrush
        End Function 'GetHalfToneBrush        Protected Shared Function GetHalfToneBrush() As IntPtr
            If _halfToneBrush.Equals(IntPtr.Zero) Then
                Dim bitmap As New bitmap(8, 8, PixelFormat.Format32bppArgb)                Dim white As Color = Color.FromArgb(255, 255, 255, 255)
                Dim black As Color = Color.FromArgb(255, 0, 0, 0)                Dim flag As Boolean = True                ' Alternate black and white pixels across all lines
                Dim x As Integer
                While x < 8
                    Dim y As Integer
                    While y < 8
                        Dim tempColor As Color
                        If flag Then
                            tempColor = Color.White
                        Else
                            tempColor = Color.Black
                        End If
                        bitmap.SetPixel(x, y, tempColor)
                    End While
                End While
                Dim hBitmap As IntPtr = bitmap.GetHbitmap()                Dim brush As New Win32.LOGBRUSH                brush.lbStyle = Convert.ToUInt32(Win32.BrushStyles.BS_PATTERN)
                brush.lbHatch = Convert.ToUInt32(hBitmap)                _halfToneBrush = Gdi32.CreateBrushIndirect(brush)
            End If
            Return _halfToneBrush
        End Function 'GetHalfToneBrush

解决方案 »

  1.   

    其实就这一小段有问题:
    for(int x=0; x<8; x++, flag = !flag)
                        for(int y=0; y<8; y++, flag = !flag)
                            bitmap.SetPixel(x, y, (flag ? white : black));
    其他的偶都会!
    帮忙!
      

  2.   

    想明白了。应该改为:
     For x = 0 To 8 - 1
                        flag = Not flag
                        For y = 0 To 8 - 1
                            flag = Not flag
                            Dim tempColor As Color
                            If flag Then
                                tempColor = Color.White
                            Else
                                tempColor = Color.Black
                            End If
                            bitmap.SetPixel(x, y, tempColor)
                        Next
                    Next本贴当作从分。先到先得得·!!