Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. FillRect with CBrush question

FillRect with CBrush question

Scheduled Pinned Locked Moved C / C++ / MFC
questioncomgraphics
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LukeV
    wrote on last edited by
    #1

    Hi! When I call FillRect with a brush created from a bitmap, the rect will get filled but the bitmap is tiled, even though the rect and bitmap size are the same (20 X 20). Is there a reason for that? I thought the bitmap would get displayed correctly! Screenshot at www.edovia.com/pictures/FillRect.png[^] //Draw thumb RECT rectThumb; hBitmap = (HBITMAP)LoadImage(NULL, m_szThumb, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADTRANSPARENT); bitmapThumb.Detach(); bitmapThumb.Attach( hBitmap ); bitmapThumb.GetBitmap( &bmp ); rectThumb.top = rectFill.bottom; rectThumb.bottom = rectThumb.top + bmp.bmHeight; rectThumb.left = roundf( ( rectClient.Width() - bmp.bmWidth ) / 2 ); rectThumb.right = rectThumb.left + bmp.bmWidth; brush.CreatePatternBrush( &bitmapThumb ); memDC.FillRect( &rectThumb, &brush ); brush.DeleteObject();

    V S 2 Replies Last reply
    0
    • L LukeV

      Hi! When I call FillRect with a brush created from a bitmap, the rect will get filled but the bitmap is tiled, even though the rect and bitmap size are the same (20 X 20). Is there a reason for that? I thought the bitmap would get displayed correctly! Screenshot at www.edovia.com/pictures/FillRect.png[^] //Draw thumb RECT rectThumb; hBitmap = (HBITMAP)LoadImage(NULL, m_szThumb, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADTRANSPARENT); bitmapThumb.Detach(); bitmapThumb.Attach( hBitmap ); bitmapThumb.GetBitmap( &bmp ); rectThumb.top = rectFill.bottom; rectThumb.bottom = rectThumb.top + bmp.bmHeight; rectThumb.left = roundf( ( rectClient.Width() - bmp.bmWidth ) / 2 ); rectThumb.right = rectThumb.left + bmp.bmWidth; brush.CreatePatternBrush( &bitmapThumb ); memDC.FillRect( &rectThumb, &brush ); brush.DeleteObject();

      V Offline
      V Offline
      Viorel
      wrote on last edited by
      #2

      Description of CreatePatternBrush says that Windows uses only the first 8 rows and columns of pixels from the bitmap you supplied. If you just need to display an image, why do not use bitmap-drawing functions, like BitBlt?

      L 1 Reply Last reply
      0
      • L LukeV

        Hi! When I call FillRect with a brush created from a bitmap, the rect will get filled but the bitmap is tiled, even though the rect and bitmap size are the same (20 X 20). Is there a reason for that? I thought the bitmap would get displayed correctly! Screenshot at www.edovia.com/pictures/FillRect.png[^] //Draw thumb RECT rectThumb; hBitmap = (HBITMAP)LoadImage(NULL, m_szThumb, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADTRANSPARENT); bitmapThumb.Detach(); bitmapThumb.Attach( hBitmap ); bitmapThumb.GetBitmap( &bmp ); rectThumb.top = rectFill.bottom; rectThumb.bottom = rectThumb.top + bmp.bmHeight; rectThumb.left = roundf( ( rectClient.Width() - bmp.bmWidth ) / 2 ); rectThumb.right = rectThumb.left + bmp.bmWidth; brush.CreatePatternBrush( &bitmapThumb ); memDC.FillRect( &rectThumb, &brush ); brush.DeleteObject();

        S Offline
        S Offline
        Sarath C
        wrote on last edited by
        #3

        http://www.codeproject.com/gdi/custom_pattern_brush.asp[^] SaRath.
        "Don't Do Different things... Do Things Differently..."

        1 Reply Last reply
        0
        • V Viorel

          Description of CreatePatternBrush says that Windows uses only the first 8 rows and columns of pixels from the bitmap you supplied. If you just need to display an image, why do not use bitmap-drawing functions, like BitBlt?

          L Offline
          L Offline
          LukeV
          wrote on last edited by
          #4

          BitBlt did the trick... thanks! :)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups