|
-
Dec 4th, 2001, 05:24 PM
#1
Thread Starter
Hyperactive Member
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
-
Dec 4th, 2001, 05:54 PM
#2
Good Ol' Platypus
I believe the picture format is BGR. Therefore, you could do this:
VB Code:
For J = LBound(PicBits,2) To Ubound(PicBits,2)
For I = Lbound(picBits,1) To Ubound(PicBits,1) Step PicInfo.bmBitsPixel
R = picBits(I+2,J)
G = picBits(I+1,J)
B = picBits(I,J)
Next I
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:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|