Re: GetDIBBits does not fill the array corectly
- From: "Michael Phillips, Jr." <mphillips53@xxxxxxxxxxxxxxx>
- Date: Thu, 9 Aug 2007 14:50:42 -0400
If I get an array of Bytes can I pass that to CreateDIBSection some how
You use GetDIBits to retieve a bitmap's bits out of an existing GDI DIB.
You use it the same way you would use Lockbits to retrieve the bits out of
an existing System.Drawing.Bitmap.
" active" <activeNOSPAM@xxxxxxxxxx> wrote in message
news:uf%23pfMr2HHA.728@xxxxxxxxxxxxxxxxxxxxxxx
Am I going about this correctly.
All I'm trying to do is to fill in a BitmapInfo structure to use with
CreateDIBSection
If I get an array of Bytes can I pass that to CreateDIBSection some how
thanks again
"Michael Phillips, Jr." <mphillips53@xxxxxxxxxxxxxxx> wrote in message
news:OCGuCrq2HHA.4880@xxxxxxxxxxxxxxxxxxxxxxx
In order to use GetDIBits you should use a memory device context not the
desktop's display context.
You also need to allocate memory for the number of scanlines that you
wish to retrieve.
You can pass a managed memory array of bytes where the number of
allocated bytes is equal to bmi.bmiHeader.biSizeImage.
IntPtr hdc = GetDC(IntPtr.Zero)
IntPtr hdcMem = CreateCompatibleDC(hdc)
int nScanlinesRetrieved = GetDIBits(hdcMem, hBitmap, 0, nScanlines,
pBits, bmi, DIB_RGB_COLORS)
nScanlines can be 1 to Height of your bitmap
Don't forget to free gdi resources(i.e, device contexts)
" active" <activeNOSPAM@xxxxxxxxxx> wrote in message
news:eJDc4Qq2HHA.2064@xxxxxxxxxxxxxxxxxxxxxxx
I have another post asking how to fill in the structure but I now think
GetDIBBits is the way, I just can't get it to work!
I can make the following run but GetDIBBits does not fill the array to
correctly reflect the data from the bitmap.
Any helpful suggestions would be appreciated.
Dim hInBitmap As IntPtr = InBitmap.GetHbitmap()
'Dim hInBitmapDC As IntPtr = GetDC(hInBitmap)
Dim hInBitmapDC As IntPtr = GetDC(Nothing)
Dim dibInfo As New BitmapInfo
Dim dibInfoPtr As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(dibInfo))
If GetDIBits(hInBitmapDC, hInBitmap, 0, 0, Nothing, dibInfoPtr,
DIB_RGB_COLORS) = 0 Then
DeleteObject(hInBitmap)
Exit Sub
End If
dibInfo = CType(Marshal.PtrToStructure(dibInfoPtr, dibInfo.GetType),
BitmapInfo)
Marshal.FreeHGlobal(dibInfoPtr)
ReleaseDC(hInBitmap, hInBitmapDC)
Above: Don't know which GetDC is correct?
Public Declare Auto Function GetDIBits Lib "gdi32" (ByVal hDC As IntPtr,
ByVal hBitmap As IntPtr, ByVal nStartScan As Integer, ByVal nNumScans As
Integer, ByRef lpBits As Byte, ByRef lpBI As IntPtr, ByVal wUsage As
Integer) As Integer
Above: Do not know how to use lpBI As BitmapInfo - would that be better?
Below: Don't know how to set the array size at run time when I know how
many colors there are?
Public Structure BitmapInfo
Public bmiHeader As BitmapInfoHeader
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=256)> Public bmiColors()
As RGBQuad
End Structure
Public Structure BitmapInfoHeader
Public biSize As Integer
Public biWidth As Integer
Public biHeight As Integer
Public biPlanes As Short
Public biBitCount As Short
Public biCompression As Integer
Public biSizeImage As Integer
Public biXPelsPerMeter As Integer
Public biYPelsPerMeter As Integer
Public biClrUsed As Integer
Public biClrImportant As Integer
End Structure
Public Structure RGBQuad
Public rgbBlue As Byte
Public rgbGreen As Byte
Public rgbRed As Byte
Public rgbReserved As Byte
End Structure
.
- Follow-Ups:
- Re: GetDIBBits does not fill the array corectly
- From: active
- Re: GetDIBBits does not fill the array corectly
- References:
- GetDIBBits does not fill the array corectly
- From: active
- Re: GetDIBBits does not fill the array corectly
- From: Michael Phillips, Jr.
- Re: GetDIBBits does not fill the array corectly
- From: active
- GetDIBBits does not fill the array corectly
- Prev by Date: Re: GetDIBBits does not fill the array corectly
- Next by Date: Re: How to free memory allocated in C function
- Previous by thread: Re: GetDIBBits does not fill the array corectly
- Next by thread: Re: GetDIBBits does not fill the array corectly
- Index(es):
Relevant Pages
|