Results 1 to 5 of 5

Thread: YoungBuck plz - Get & SetBitmapBits

  1. #1

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    You said you could do a tutorial on this

    Can you show me how (I lost my VB5 Graphics programming book)
    (yes, and dont laugh at me for losing a book)
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  2. #2
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    I never said that (at least not that I'm aware of, maybe I said it in an alcohol induced stupor) Sastraxi I've never used either one of those functions. I'll see if I can figure them out though.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  3. #3
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Maybe this will help...

    Code:
    Option Explicit
    Private Const BI_RGB = 0&
    Private Const DIB_RGB_COLORS = 0 '  color table in RGBs
    Private 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 Long
    End Type
    Private Type RGBQUAD
            rgbBlue As Byte
            rgbGreen As Byte
            rgbRed As Byte
            rgbReserved As Byte
    End Type
    Private Type BITMAPINFO
            bmiHeader As BITMAPINFOHEADER
            bmiColors As RGBQUAD
    End Type
    Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
    Private 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 Long
    Private 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 Long
    Private 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 Long
    Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
    Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    Private 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 Long
    Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    
    Dim iBitmap As Long, iDC As Long
    Private Sub Form_Paint()
        'KPD-Team 2000
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        '-> 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 iBitmap
    End Sub
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  4. #4

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    The SetPixelV would probably be the fastest way to draw directly to the picturebox. If this isn't fast enough you can draw directly to an offscreen DC and then just blt it directly from memory into the picture box (alot more code), let me know if you need an example for that....

    -YoungBuck
    You said that, and I thought it must mean using Get&Set bitmap bits because I had heard of it and I knew that that's what it did.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5

    Thread Starter
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Anyways, I think I have found a much more simple way, using only GetObject, SetBitmapBits, and GetBitmapBits!

    Code:
    'mod1.bas
    Public ColourCodes() as Long
    Public HookIM as Long
    
    Public WW
    Public HH
    
    
    Public Declare Function GetBitmapBits Lib "gdi32" 
    Alias "GetBitmapBits" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
    
    Public Declare Function SetBitmapBits Lib "gdi32" Alias "SetBitmapBits" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
    
    Public Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
    
    Public Type BITMAP '14 bytes
            bmType As Long
            bmWidth As Long
            bmHeight As Long
            bmWidthBytes As Long
            bmPlanes As Integer
            bmBitsPixel As Integer
            bmBits As Long
    End Type
    
    Public iBit as BITMAP
    Public NullBitmap as BITMAP
    
    Function HookBitmap(bImage as Long)
    
       hookIM = bImage
       HookBitmap = GetObject(bImage,14,iBit)
    
    End Function
    
    Function DestroyHook()
    
       Set iBit = NullBitmap
    
    End Function
    
    Function GetPixels
    
       ww=iBit.bmWidth
       hh=iBit.bmHeight
       ReDim ColourCodes(1 to ww, 1 to hh) as Long
       GetPixels = GetBitmapBits(hookIM,ww*hh,ColourCodes(1,1))
    
    End Function
    
    Function SetPixels
    
       SetPixels = SetBitmapBits(hookIM,ww*hh,ColourCodes(1,1))
    
    End Function
    Usage:

    Code:
    Picture1.AutoRedraw = True
    
    HookBitmap Picture1.Image
    GetPixels
    
    For I = 1 to WW
    For J = 1 to HH
    
    Randomize
    ColourCodes(I,J)=RGB(RND*255,RND*255,RND*255)
    
    Next J
    Next I
    
    SetPixels
    DestroyHook
    
    Picture1.Refresh
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width