Results 1 to 5 of 5

Thread: [RESOLVED] SetDIBitsToDevice question

  1. #1

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Resolved [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)

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    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)

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: SetDIBitsToDevice question

    Quote Originally Posted by LaVolpe View Post
    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
  •  



Click Here to Expand Forum to Full Width