+ -
当前位置:首页 → 问答吧 → VB如何二值化图片?

VB如何二值化图片?

时间:2011-08-01

来源:互联网

一幅BMP图片,需要通过串口发送出去,想到了把图片二值化处理后发出去,但我无法实现。请高手指点方向!

作者: BlueBinaryMan   发布时间: 2011-08-01

VB code

Option Explicit
Private Type bitmapfileheader
    bftype As Integer
    bfsize As Long
    bfreserved1 As Integer
    bfreserved2 As Integer
bfoffbits As Long
End Type
'头信息
Private Type bitmapinfoheader
    bisize As Long
    biwidth As Long
    biheight As Long
    biplanes As Integer
    bibitcount As Integer
    bicompression As Long
    bisizeimage As Long
    bixpelspermeter As Long
    biypelspermeter As Long
    biclrused As Long
    biclrimportant As Long
End Type
Private Type RGBQUAD
        rgbBlue As Byte
        rgbReserved As Byte
        rgbRed As Byte
        rgbGreen As Byte
End Type

Dim FileHeader As bitmapfileheader
Dim FileInfoHeader As bitmapinfoheader
Dim Palettesize As Integer
Dim BMPFileToBinary(1024, 1024, 2) As Byte

Private Sub btnBMP_Click()
    Dim lngBMPWidth As Long     'BMP图片的宽
    Dim lngBMPHeight As Long    'BMP图片的高
    Dim intBMPBitCount As Long  'BMP图片的位数
    Dim bytPoint As Byte
    Dim bytPalentry As Byte
    Dim bytP As Byte
    Dim intP As Integer
    Dim intT As Integer
    Dim intC As Integer
    Dim intD As Integer
On Error GoTo errSub
    Open "D:\Test.bmp" For Binary As #1
    Get #1, , FileHeader
    Get #1, , FileInfoHeader
    lngBMPWidth = FileInfoHeader.biwidth
    lngBMPHeight = FileInfoHeader.biheight
    intBMPBitCount = FileInfoHeader.bibitcount

    For intP = 0 To lngBMPHeight - 1
        For intT = 0 To lngBMPWidth - 1
            For intC = 0 To 2
                Get #1, , bytPoint
                BMPFileToBinary(intT, intP, intC) = bytPoint
            Next intC
        Next intT
    Next intP
       
    Close #1
    Exit Sub
errSub:

End Sub


作者: Veron_04   发布时间: 2011-08-01

二值化发过去,这还能看么?

作者: WallesCai   发布时间: 2011-08-03

学习了,我就需要这个一个二值化,将图像转为黑白的知识,这个在扫描上用处大大的和图像数据库转换和压缩很有用

作者: xiaolinyouni   发布时间: 2011-08-03

热门下载

更多