首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

GetDIBits 的参数有关问题

2012-04-03 
GetDIBits 的参数问题VB声明Declare Function GetDIBits Lib gdi32 Alias GetDIBits (ByVal aHDC As L

GetDIBits 的参数问题
VB声明 
Declare Function GetDIBits Lib "gdi32" Alias "GetDIBits" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long 
说明 
将来自一幅位图的二进制位复制到一幅与设备无关的位图里 
返回值 
Long,非零表示成功,零表示失败。在Windows 95中,返回值是返回的扫描线数量 
参数表 
参数 类型及说明 
aHDC Long,定义了与设备有关位图hBitmap的配置信息的一个设备场景的句柄 
hBitmap Long,源位图的句柄。绝对不能将这幅位图选入设备场景 
nStartScan Long,欲复制到DIB中的第一条扫描线的编号 
nNumScans Long,欲复制的扫描线数量 
lpBits Any,指向一个缓冲区的指针。这个缓冲区将用于装载采用DIB格式的信息,但不取回数据(用ByVal传递零值) 
lpBI BITMAPINFO,对lpBits DIB的格式及颜色进行说明的一个结构。在BITMAPINFOHEADER结构中,从biSize到biCompression之间的所有字段都必须初始化 
wUsage Long,下述常数之一: 
DIB_PAL_COLORS 在颜色表中装载一个16位所以数组,它们与当前选定的调色板有关 
DIB_RGB_COLORS 在颜色表中装载RGB颜色 
注解 
起始扫描线与起点有关。除非将BITMAPINFOHEADER结构的biHeight字段设为负值,否则起点就位于左下角 


上面是我的API文档里的说明,他第2个参数说"绝对不能将这幅位图选入设备场景",这句话怎么理解呢??

如果我这样写
mHdc = CreateCompatibleDC(0)
mDib = CreateDIBSection(mHdc, bMapinfo, DIB_RGB_COLORS, mPtr, 0, 0)
mOldDib = SelectObject(mHdc, mDib)

GetDIBits mHdc, mDib, 0, lHeight, p(1, 1), bMapinfo, DIB_RGB_COLORS
这样可以吗?还是必须把mHdc换成GetDC(0)啥的???

[解决办法]

VB code
'Example Name:DIBPrivate Const BI_RGB = 0&Private Const DIB_RGB_COLORS = 0 '  color table in RGBsPrivate Type BITMAPINFOHEADER '40 bytes        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 LongEnd TypePrivate Type RGBQUAD        rgbBlue As Byte        rgbGreen As Byte        rgbRed As Byte        rgbReserved As ByteEnd TypePrivate Type BITMAPINFO        bmiHeader As BITMAPINFOHEADER        bmiColors As RGBQUADEnd TypePrivate Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As LongPrivate Declare Function CreateDIBSection Lib "gdi32" (ByVal hdc As Long, pBitmapInfo As BITMAPINFO, ByVal un As Long, ByVal lplpVoid As Long, ByVal handle As Long, ByVal dw As Long) As LongPrivate Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As LongPrivate Declare Function SetDIBitsToDevice Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal dx As Long, ByVal dy As Long, ByVal SrcX As Long, ByVal SrcY As Long, ByVal Scan As Long, ByVal NumScans As Long, Bits As Any, BitsInfo As BITMAPINFO, ByVal wUsage As Long) As LongPrivate Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As LongPrivate Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As LongPrivate Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As LongPrivate Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As LongPrivate Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As LongDim iBitmap As Long, iDC As LongPrivate Sub Form_Paint()    'KPD-Team 2000    'URL: http://www.allapi.net/    'E-Mail: KPDTeam@Allapi.net    '-> Compile this code for better performance    Dim bi24BitInfo As BITMAPINFO, bBytes() As Byte, Cnt As Long    With bi24BitInfo.bmiHeader        .biBitCount = 24        .biCompression = BI_RGB        .biPlanes = 1        .biSize = Len(bi24BitInfo.bmiHeader)        .biWidth = 100        .biHeight = 100    End With    ReDim bBytes(1 To bi24BitInfo.bmiHeader.biWidth * bi24BitInfo.bmiHeader.biHeight * 3) As Byte    iDC = CreateCompatibleDC(0)    iBitmap = CreateDIBSection(iDC, bi24BitInfo, DIB_RGB_COLORS, ByVal 0&, ByVal 0&, ByVal 0&)    SelectObject iDC, iBitmap    BitBlt iDC, 0, 0, bi24BitInfo.bmiHeader.biWidth, bi24BitInfo.bmiHeader.biHeight, GetDC(0), 0, 0, vbSrcCopy    GetDIBits iDC, iBitmap, 0, bi24BitInfo.bmiHeader.biHeight, bBytes(1), bi24BitInfo, DIB_RGB_COLORS    For Cnt = LBound(bBytes) To UBound(bBytes)        If bBytes(Cnt) < 50 Then            bBytes(Cnt) = 0        Else            bBytes(Cnt) = bBytes(Cnt) - 50        End If    Next Cnt    SetDIBitsToDevice Me.hdc, 0, 0, bi24BitInfo.bmiHeader.biWidth, bi24BitInfo.bmiHeader.biHeight, 0, 0, 0, bi24BitInfo.bmiHeader.biHeight, bBytes(1), bi24BitInfo, DIB_RGB_COLORS    DeleteDC iDC    DeleteObject iBitmapEnd Sub 

热点排行