已经得到了一个设备的Hdc,怎么才能对其进行DIB处理呢?就是说,怎么才能把HDC中的内容复制到二进制数组中呢?哎,这两天看ZYL910的例子头都看大了,他的例子太复杂了不好看懂,那篇用VB写高效的图像处理程序中的例子ImgTest又没有涉及这些内容,刚接触这方面的知识,还望大家多多帮助哟!

解决方案 »

  1.   

    好啊,那真谢谢了!Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    private Cache() as bytePrivate Sub Command1_Click()
    'Dim WinDeskHwnd As Long, WinDeskHdc As Long
    WinDeskHwnd = GetDesktopWindow
    WinDeskHdc = GetDC(WinDeskHwnd)
    '出错陷阱
    If WinDeskHdc = 0 Then Debug.Print "GetWindowsDesktopHdc Error!": Exit Sub
    '现在要把这个WinDeskHdc中的内容复制到Cache()数组中,
    '只要告诉我怎么复制就可以了,非常感谢End Sub
      

  2.   

    Cache()数组的具体格式?
    24位?
      

  3.   

    ……
    If WinDeskHdc = 0 Then Debug.Print "GetWindowsDesktopHdc Error!": Exit Subdim hDIBDC as Long
    Dim hDIBOldMap as long
    Dim bi as BITMAPINFOHEADER
    Dim hDIB as long
    dim pDIB as longhDIBDC=CreateCompatibleDC(WinDeskHdc)
    If hDIBDC=0 then Exit SubWith bi
        .biSize=len(bi)
        .biWidth=Screen.Width\Screen.TwipsPerPixelX
        .biHeight=Screen.Height\Screen.TwipsPerPixelY
        .bibitCount=24
        .biPlanes=1
        .biCompression=BI_RGB
        .biSizeImage=((.biWidth*3+3)and &H7FFFFFFC)*.biHeight
    End With
    hDIB=CreateDIBSection(hDIBDC, bi, DIB_RGB_COLORS, pDIB,0,0)
    hDIBOldMap=SelectObject(hDIBDC,hDIB)'由于是DIBSection,可以直接用BitBlt
    BitBlt hDIBDC, 0, 0, bi.biWidth, bi.biHeight, WinDeskHdc, 0, 0, vbSrcCopyReDim Cache(0 to bi.biSizeImage-1) as Byte
    CopyMemory Cache(0), byval pDIB, bi.biSizeImage
    对Cache进行操作
    Call SelectObject(hDIBDC, hDIBOldMap)
    DeleteDC hDIBDC
      

  4.   

    注意CreateDIBSection的声明
    APIViewer 2003的是错误的应该这样:
    Public Declare Function CreateDIBSection Lib "gdi32" (ByVal hDC As Long, lpbmi As Any, ByVal iUsage As Long, ByRef ppvBits As Long, ByVal hSection As Long, ByVal dwOffset As Long) As Long
      

  5.   

    忘了释放hDIB
    Call SelectObject(hDIBDC, hDIBOldMap)
    DeleteObject hDIB
    DeleteDC hDIBDC