画出黑白Bmp文件的方法. (vb.net2005)

    Const IMAGE_BITMAP As Integer = 0    Const LR_MONOCHROME As Integer = &H1    Const LR_LOADFROMFILE As Integer = &H10

    Public Declare Function CopyImage Lib "user32" Alias "CopyImage" (ByVal handle As IntPtr, ByVal un1 As Integer, ByVal n1 As Integer, ByVal n2 As Integer, ByVal un2 As Integer) As IntPtr

    Private Sub Button100_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click        Dim fontFamily As New FontFamily("MS UI Gothic")        Dim font1 As New Font(fontFamily, 11, FontStyle.Bold, GraphicsUnit.Pixel)

        Dim brush As New SolidBrush(Color.Red)

        Dim bmp As New Bitmap(244, 368)

        Dim G As Graphics        G = Graphics.FromImage(bmp)

        G.Clear(Color.White)

        G.DrawString("Hello", font1, brush, 10, 10)        G.Dispose()

        '直接复制图形并转换         Dim hwnd As IntPtr = CopyImage(bmp.GetHbitmap, IMAGE_BITMAP, 0, 0, LR_MONOCHROME)

        If Not hwnd.Equals(IntPtr.Zero) Then            '保存成单色位图             bmp = Bitmap.FromHbitmap(hwnd)            bmp.Save("c:/abcd.bmp")        End If        bmp.Dispose()

    End Sub

你可能感兴趣的:(画出黑白Bmp文件的方法. (vb.net2005))