Announcement

Collapse
No announcement yet.

Gdi+

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Gdi+

    Hi folks,

    I am about creating an ownerdrawn button where I want to
    display a bitmap from file. The button finally will have different sizes
    when it is place on a form so I'll have to stretch the bitmap.

    I could do this with StretchBlt but the quality isn't that good.

    I've tried to use GDI+ for stretching the bitmap but I am not
    so familiar with GDI+. I was able to display the streched bitmap on
    the button but the speed of GDI+ isn't fast enough if you have lots of
    button placed on the form (that's my expierience so far).

    Therefore I would like to use only the stretch function of GDI+
    within the WM_CREATE message of the button control (it's a dll and
    we talk about SDK style). GdipDrawImageRectI stretches the bitmap
    into the right size but onto a memory device context, created by
    GdipCreatefromHDC which isn't compatible to the ordinary memory
    device context (I assume...).

    The questions is how to get the stretched bitmap back from this memory DC
    to BitBlt it onto the final device context?

    Another question is if the use of GDI+ in several usercontrols (dll) on a form
    is doable or not?

    Thank you for your help
    Joerg Koehler

  • #2
    Make sure you call:

    SetStretchBltMode

    with the %HALFTONE flag before calling StretchBlt or StretchDIBits.

    This flag works on WinXP,2000 or Vista

    It produces the best possible stretched image.

    If you don't set this flag, the default for a DC produces a poor image.

    No GDI+ needed here.
    Chris Boss
    Computer Workshop
    Developer of "EZGUI"
    http://cwsof.com
    http://twitter.com/EZGUIProGuy

    Comment


    • #3
      The best way to draw your image, for speed, is to create a bitmap perfectly sized for the button control during WM_CREATE and also WM_SIZE (if the control can be sized) and then stretch the image into it. Then when the control needs to repaint itself, BitBlt the bitmap you created.

      If you have lots of buttons, BltBit is much faster.

      Another technique which I use with ownerdraw, if you need to stretch during the repaint (WM_DRAWITEM), is to create a memory DC and a blank bitmap on the fly. Do your drawing into it first and then BitBlt the results into the controls window DC. Complex drawing into a memory DC is usually faster than drawing into a window DC (screen).

      BitBlt is optimized for speed in Windows, whereas other drawing methods may not be.
      Chris Boss
      Computer Workshop
      Developer of "EZGUI"
      http://cwsof.com
      http://twitter.com/EZGUIProGuy

      Comment


      • #4
        Hi Chris,

        Sorry for taking so long to respond but I went to Russia on business
        and I haven't had any chance to access internet there.

        A combination of %HALFTONE and resizing the original image closer to the
        used button size gave me a acceptable result.

        Thank you for you suggestion!

        Joerg
        Joerg Koehler

        Comment


        • #5
          See how to take control over YOUR buttons there

          ...
          Patrice Terrier
          www.zapsolution.com
          www.objreader.com
          Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

          Comment

          Working...
          X