-
December 20th, 2020, 12:16 PM
#1
Knowing HDC, can i get the actual DIB, or i must create it?
using the GetCurrentObject() with HDC, i can get the actual HBitmap handle....but i need ask more 2 things:
1 - how can i get the BITMAPINFOHEADER from HBitmap?
2 - do i need create the DIB or the control(form) have it's own? if have it, how can i get it?
-
December 20th, 2020, 01:50 PM
#2
Re: Knowing HDC, can i get the actual DIB, or i must create it?
so far i did these code:
Code:
Friend Sub DrawImageRectanglePoints(DestinationHDC As Long, Points() As Position3D, WorldSize As Size3D) 'Points(0) is the Upper-Left
'Points(1) is the Upper-Right
'Points(2) is the Low-Right
'Points(3) is the Low-Left
Dim x As Long
Dim y As Long
Dim PosX As Long
Dim PosY As Long
Dim DestinationBitmap As Long
Dim lpBitsDestination As Long
Dim bi As BITMAPINFO
Dim bm As BITMAP
Dim bufSize As Long
Dim ghnd As Long
Dim gptr As Long
If (hBitmap = 0 Or hMemDC = 0) Then Exit Sub
'Get actual hBitmap from Destination HDC:
DestinationBitmap = GetCurrentObject(DestinationHDC, OBJ_BITMAP)
GetObject DestinationBitmap, Len(bm), bm
'Prepare the structure for get the DIB's:
bi.bmiHeader.biSize = Len(bi.bmiHeader)
bi.bmiHeader.biWidth = bm.bmWidth
bi.bmiHeader.biHeight = bm.bmHeight
bi.bmiHeader.biPlanes = 1
' Set to 24 here to create a 24 bit DIB
' Set to 8 here to create an 8 bit DIB
bi.bmiHeader.biBitCount = 4
bi.bmiHeader.biCompression = BI_RGB
' Now calculate the data buffer size needed
bufSize = bi.bmiHeader.biWidth
' Figure out the number of bytes based on the
' number of pixels in each byte. In this case we
' really don't need all this code because this example
' always uses a 16 color DIB, but the code is shown
' here for your future reference
Select Case bi.bmiHeader.biBitCount
Case 1
bufSize = (bufSize + 7) / 8
Case 4
bufSize = (bufSize + 1) / 2
Case 24
bufSize = bufSize * 3
End Select
' And make sure it aligns on a long boundary
bufSize = ((bufSize + 3) / 4) * 4
' And multiply by the # of scan lines
bufSize = bufSize * bi.bmiHeader.biHeight
' Now allocate a buffer to hold the data
' We use the global memory pool because this buffer
' could easily be above 64k bytes.
ghnd = GlobalAlloc(GMEM_MOVEABLE, bufSize)
gptr = GlobalLock(ghnd)
'get DIB's from HBitmap, on Destination HDC:
Dim s As Long
s = GetDIBits(DestinationHDC, DestinationBitmap, 0, bm.bmHeight, gptr, bi, DIB_RGB_COLORS)
If (s = 0) Then
MsgBox "error"
Exit Sub
End If
Dim pixels3() As COLORQUAD
Dim uarray2d3 As SAFEARRAY
GetPixelArray pixels3, uarray2d3, gptr, bm.bmWidth, bm.bmHeight
maybe the 'gptr' is wrong and i don't know it... what i'm doing wrong?
yes i get zero... the GetDIBits() is falling
-
December 20th, 2020, 05:25 PM
#3
Re: Knowing HDC, can i get the actual DIB, or i must create it?
What does GetLastError() tell you?
-
December 21st, 2020, 04:45 PM
#4
Re: Knowing HDC, can i get the actual DIB, or i must create it?
both zero
Code:
Dim s As Long s = GetDIBits(DestinationHDC, DestinationBitmap, 0, bm.bmHeight, gptr, bi, DIB_RGB_COLORS)
If (s = 0) Then
MsgBox "error " + vbTab + CStr(GetLastError())
Exit Sub
End If
i belive the problem is with:
Code:
Public Const GMEM_MOVEABLE = &H2
Public Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Public Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
...............
ghnd = GlobalAlloc(GMEM_MOVEABLE, bufSize)
gptr = GlobalLock(ghnd)
but i can be wrong.
Note: i know these is C\C++ subforum and not VB... was my mistake speed
sometimes happens... if you can change the subforum, please do it... i'm sorry
-
December 21st, 2020, 05:03 PM
#5
Re: Knowing HDC, can i get the actual DIB, or i must create it?
[Moved from C++ and WinAPI forum]
Last edited by VictorN; December 21st, 2020 at 05:06 PM.
Victor Nijegorodov
-
December 21st, 2020, 05:21 PM
#6
Re: Knowing HDC, can i get the actual DIB, or i must create it?
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
|