'这段程序运行不正确,而下面一样逻辑的却又正确,为何。
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, Source As Any, ByVal Length As Long)
Private Type BitmapFileHeader
    bfType As Integer           '说明文件的类型,该值必定是0x424D,也就是字符'BM'。
    bfSize As Long              '说明文件的大小,用字节为单位
    bfReserved1 As Integer      '保留,该值必定为0
    bfReserved2 As Integer      '保留,该值必定为0
    bfOffBits As Long           '位图数据的起始位置
End Type
Private Function GetBitmapFileHeader(bitMap() As Byte) As BitmapFileHeader
     CopyMemory GetBitmapFileHeader, bitMap(0), LenB(GetBitmapFileHeader)
End Function'这段代码运行的结果正确的
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, Source As Any, ByVal Length As Long)
Private Type BitmapInfoHeader
    biSize As Long              'BitmapInfoHeader结构的大小
    biWidth As Long             '图片的宽度,以象素为单位。
    biHeight As Long            '图片的高度,以象素为单位。
    biPlanes As Integer         '为目标设备说明位面数,其值将总是被设为1
    biCount As Integer          '说明一个像素需要的位数,其值为1、4、8、16、24、或32。
    biCompression As Long       '说明图像数据压缩的类型
    biImageSize As Long         '表示位图数据区域的大小以字节为单位
    biXPelsPerMeter As Long     '说明水平分辨率,用象素/米表示
    biYPelsPerMeter As Long     '说明垂直分辨率,用象素/米表示
    biClrUsed As Long           '说明位图实际使用的彩色表中的颜色索引数
    biClrImprotant As Long      '说明对图像显示有重要影响的颜色索引的数目,如果是0,表示都重要。
End Type
Private Function GetBitmapInfoHeader(bitMap() As Byte) As BitmapInfoHeader
    CopyMemory GetBitmapInfoHeader, bitMap(14), LenB(GetBitmapInfoHeader)
End Function

解决方案 »

  1.   

    请来接分,问题解决的,是字节对齐的问题。我干脆直接这样解决了
          CopyMemory GetBitmapFileHeader.bfType, bitMap(0), 2
         CopyMemory GetBitmapFileHeader.bfSize, bitMap(2), 4
         CopyMemory GetBitmapFileHeader.bfReserved1, bitMap(6), 2
         CopyMemory GetBitmapFileHeader.bfReserved2, bitMap(8), 2
         CopyMemory GetBitmapFileHeader.bfOffBits, bitMap(10), 4