BitBlt with mirroring
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: BitBlt with mirroring

  1. #1
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,722

    BitBlt with mirroring

    Hello my friends,

    this is one for graphics and API masters.

    I'm playing with some graphical functions, where I copy a bitmap from a picturebox' hDC to a hDC of a Form.
    I have already used the BitBlt, StretchBlt which allows resizing and AlphaBlend which allows resizing AND transparency. Great.

    Now I'd have to flip or mirror the bitmap when transfering. Is there an API call which does it?
    Or is there an option in the ROp parameter which specifies mirroring? They are only raster operations as I presume...

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,823

    Re: BitBlt with mirroring

    I found this posted on another forum maybe it will help?
    You can do it, just specify negative values for you Width and/or Height (you'll have to use StrechBlt instead of BitBlt). For example:
    Code:
    'Assumes the picture is named deer.bmp in the current directory
    Picture1.Picture = LoadPicture(App.Path & "\deer.bmp") 
    
    'Draw the picture normally (left-facing deer)
    BitBlt Me.hdc, 0, 0, Picture1.Width, Picture1.Height, Picture1.hdc, 0, 0, SRCCOPY
    
    'Draw the left/right mirror (right-facing deer)
    StretchBlt Me.hdc, Picture1.Width, 0, Picture1.Width, Picture1.Height, Picture1.hdc, Picture1.Width, 0, -Picture1.Width, Picture1.Height, SRCCOPY
    Explanation:
    The first param is the DC of the form

    The next 4 params are the coords on your picture box that you're drawing to (41, 0, 41, 34 for your deer picture). The first 41 is to draw the picture 41 pixels to the right, so as to be next to the first picture (drawn with BitBlt)

    Then comes the source picture (Picture1's DC, a picturebox)

    The next two normally specify the upper-left corner of the source picture, as an offset (most commonly 0,0). Because we'll be specifying a negative width, we'll have to offset the X value by the same amount (the width of the picture). We're not flipping the picture up/down, so the Y is left at 0.

    The next two specify the width and height. The width is negative - this gives the mirrored image. The height is left at the original value (Picture1.Height).

    Hope that helps.

    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,722

    Re: BitBlt with mirroring

    That looks promising. Thank you, DataMiser.
    However I tried negative sizes with Alphablend, but this didn't work, although I did not offset the X origin by the width, as described here
    I will try it tomorrow if AlphaBlend accepts the negative values, too. If not I will have to use StretchBlt to mirror to a buffer PictureBox and then AlphaBlend it from there.
    Thanks again.

  4. #4
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,722

    Re: BitBlt with mirroring

    Ok, thanks again for bringing me on the way.
    StretchBlt works as you described. Unfortunately AlphaBlend does not share this feature, so I would have to mirror to a buffer and then Blend, but no matter the mirroring works fine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center