基本理解bitmap的文件结构.

昨天在看vbaccelerator的分隔条类

看到:

Private m_lPattern(0 To 3) As Long

   Dim i As Long
   For i = 0 To 3
      m_lPattern(i) = &HAAAA5555 作者在此处写了一个十六进制,开始我很不理解.
   Next i

Dim tbm As BITMAP
Dim hBm As Long
     
   ' Create a monochrome bitmap containing the desired pattern:
   tbm.bmType = 0
   tbm.bmWidth = 16
   tbm.bmHeight = 8
   tbm.bmWidthBytes = 2
   tbm.bmPlanes = 1
   tbm.bmBitsPixel = 1
   tbm.bmBits = VarPtr(m_lPattern(0))

   hBm = CreateBitmapIndirect(tbm)

   ' Make a brush from the bitmap bits
   m_hBrush = CreatePatternBrush(hBm)

--------------------------
其实蓝色部,包括 hBm = CreateBitmapIndirect(tbm) 可以用下面这个代替更为简单
Private Declare Function CreateBitmap Lib "gdi32" Alias "CreateBitmap" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long

hBm=CreateBitmap(16,8,1,1,m_lPattern(0))  这句代替就可以了

其中&HAAAA5555  它的二进制是

0123456789ABCDEF  

-------------------------

1010101010101010

0101010101010101

------------------------

所以4个数组元素就相当于8个像素的高度 宽度就是16个像素

这样在鼠标移动事件中,把这个位图填到一个很长的矩形,就像在拖一个虚线一样了.

最后感谢csdn这篇文章:http://blog.csdn.net/cnyu/archive/2009/07/12/4342562.aspx (纯手写bmp图片)的作者, 使我更加清楚的明白了bitmap的文件存储形式.而且这个博客作者,的汇编教程写得很有趣.改时间一定好好按他教程自已亲手实践一下.^_^

posted on 2009-07-31 23:08  杨志农  阅读(207)  评论(0)    收藏  举报

导航