|
-
Dec 9th, 2009, 12:36 PM
#1
[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?
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Dec 9th, 2009, 02:37 PM
#2
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
Last edited by LaVolpe; Dec 9th, 2009 at 03:10 PM.
-
Dec 10th, 2009, 04:08 AM
#3
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.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Dec 10th, 2009, 09:30 AM
#4
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.
-
Dec 10th, 2009, 09:42 AM
#5
Re: SetDIBitsToDevice question
 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.
Last edited by krtxmrtz; Dec 11th, 2009 at 04:30 AM.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
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
|