Results 1 to 2 of 2

Thread: Changing colors through GetBitmapBits

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485

    Changing colors through GetBitmapBits

    Hi

    This looked like it could be a pretty good way to swap colors but I'm not able to extract the RGB components from the bits. Any help or suggestions would be really appreciated.

    vb code:

    Private Type BITMAP
    bmType As Long
    bmWidth As Long
    bmHeight As Long
    bmWidthBytes As Long
    bmPlanes As Integer
    bmBitsPixel As Integer
    bmBits As Long
    End Type
    Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
    Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
    Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
    Dim PicBits() As Byte, PicInfo As BITMAP
    Dim Cnt As Long, BytesPerLine as Long
    Private Sub Command1_Click()

    GetObject Picture1.Image, Len(PicInfo), PicInfo
    BytesPerLine = (PicInfo.bmWidth * 3 + 3) And &HFFFFFFFC
    ReDim PicBits(1 To BytesPerLine * PicInfo.bmHeight * 3) As Byte
    GetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)
    For Cnt = 1 To UBound(PicBits)
    PicBits(Cnt) = 'How do I get and assign RGB colors here from PicBits(Cnt) ?
    Next Cnt
    SetBitmapBits Picture1.Image, UBound(PicBits), PicBits(1)
    Picture1.Refresh
    End Sub

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I believe the picture format is BGR. Therefore, you could do this:
    VB Code:
    1. For J = LBound(PicBits,2) To Ubound(PicBits,2)
    2.     For I = Lbound(picBits,1) To Ubound(PicBits,1) Step PicInfo.bmBitsPixel
    3.         R = picBits(I+2,J)
    4.         G = picBits(I+1,J)
    5.         B = picBits(I,J)
    6.     Next I
    7. Next J
    I think you can init the array like the following: (remember, you'll need to do this to work that above example)
    VB Code:
    1. Redim PicBits(1 To BytesPerLine, 1 To picInfo.bmHeight)
    The R G B information is stored "horizontally" in the array, meaning that the Width is bigger than it actually is.
    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