FillRect with CBrush question
-
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();
-
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();
-
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();
-
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, likeBitBlt
?