[RESOLVED] SetDIBitsToDevice question
Given this API declaration,
Code:
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
what parameter must be changed and how so that the image is not plotted upside down?
Re: SetDIBitsToDevice question
A couple of solutions should work
1. Don't create the source DIB top down, i.e., using a negative .biHeight member of the BitmapInfoHeader UDT.
Edited: This should not be the problem. If it was created top down, API will know it and display it properly.
2. Change signs of your BitmapInfoHeader.biHeight passed as the BitsInfo parameter, i.e., .biHeight = -.biHeight, before you call SetDIBitsToDevice.
Is it possibly you inverted the .biHeight value somewhere?
Code:
Dim BI As BITMAPINFO
Dim bArr() As Byte
' ... get dib bits and put into bArr(), then:
With BI.bmiHeader
.biHeight = -.biHeight
SetDIBitsToDevice Picture1.hdc, 0, 0, .biWidth, Abs(.biHeight), 0, 0, 0, Abs(.biHeight), bArr(0), BI, 0&
End With
Re: SetDIBitsToDevice question
The thing is, after calling SetDIBitsToDevice there is a further manipulation.
First, a bitmap in a 1D array is copied into an invisible picturebox by means of SetDIBitsToDevice. Thereafter, this image is copied into a visible picturebox, stretching it as needed. But I recall having read somewhere some time ago that SetDIBitsToDevice (or am I confusing it with some other function?) always yields the image upside down, so I was trying to take care of that by stretching like this:
StretchBlt picDst.hdc, xDst, yDst, wDst, hDst, picSrc.hdc, 0, picSrc.ScaleHeight - 1, picSrc.ScaleWidth, -picSrc.ScaleHeight, vbSrcCopy
rather than:
StretchBlt picDst.hdc, xDst, yDst, wDst, hDst, picSrc.hdc, 0, 0, picSrc.ScaleWidth, picSrc.ScaleHeight, vbSrcCopy
Using the latter statement produces the correct result..
So, the thread should be resolved, but I'm still confused about my underlined statement above.
Re: SetDIBitsToDevice question
SetDIBitsToDevice and other rendering GDI APIs do not invert the image unless you intentionally flip it as you did with your 1st StretchBlt sample code.
CreateDIBSection does create an image upside down by default; just the way Windows stores these. To create it top down the image's bitmapinfoheader biHeight value is negative vs. positive.
When you use GetDIBits API you can invert the returned image bits by providing a negative biHeight value in the API call. People do this quite often when manipulating the bits because they like to loop from top down vs bottom up. However, it is just as easy to set your loop so it goes from bottom to top instead and you don't have to mess with flipping the image/bits.
Re: SetDIBitsToDevice question
Quote:
Originally Posted by
LaVolpe
SetDIBitsToDevice and other rendering GDI APIs do not invert the image...
CreateDIBSection does create an image upside down by defauly...
I see, so I had the wrong function in mind.