April 21st, 1999, 02:16 AM
I am facing a problem using CDC::StretchBlt() function. I have loaded a 256 color bitmap onto a CBitmap object. Created a mem dc and loaded this bitmap onto it. I have also used a palette so that 256 color bitmap is shown properly. Then I am trying to do a StretchBlt on a rectangle which is of size 10 x 10 pixels. Now the bitmap is shown cluttered and distorted when the StretchBlt rectangle size is small but shows considerably clear when the rectangle size is larger.
My query is does StretchBlt have any limitation while displaying bitmaps on smaller rectangle? Any help will be highly appreciated. Please treat this as urgent.
Code snippet:
void CIMGObject::Draw(CDC *pDC)
{
CBitmap bitmap;
CDC memDC;
CPalette palette;
memDC.CreateCompatibleDC(pDC); //creates memory DC
GetBitmapAndPalette( IDB_PICTURE, bitmap, palette ); //Creates palette for //256 color bitmap
memDC.SelectObject( &bitmap ); // Select and realize the palette
if( pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE && palette.m_hObject != NULL )
{
pDC->SelectPalette( &palette, FALSE );
pDC->RealizePalette();
}
BITMAP bm;
CBitmap *pOldBm = memDC.SelectObject(&bitmap); //Store the previous bmp
HBITMAP hBmp = (HBITMAP)pOldBm->GetSafeHandle();
bitmap.GetObject(sizeof(bm), &bm);
CRect rect(0, 0, 10, 10);
pDC->StretchBlt(rect.left, rect.top, rect.Width() , rect.Height(), &memDC,
0,0, bm.bmWidth, bm.bmHeight,SRCCOPY);
//Distorted bitmap is displayed if rect size is smaller than bitmap size.
::SelectObject(memDC.m_hDC, hBmp);
bitmap.DeleteObject();
memDC.DeleteDC();
}
My query is does StretchBlt have any limitation while displaying bitmaps on smaller rectangle? Any help will be highly appreciated. Please treat this as urgent.
Code snippet:
void CIMGObject::Draw(CDC *pDC)
{
CBitmap bitmap;
CDC memDC;
CPalette palette;
memDC.CreateCompatibleDC(pDC); //creates memory DC
GetBitmapAndPalette( IDB_PICTURE, bitmap, palette ); //Creates palette for //256 color bitmap
memDC.SelectObject( &bitmap ); // Select and realize the palette
if( pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE && palette.m_hObject != NULL )
{
pDC->SelectPalette( &palette, FALSE );
pDC->RealizePalette();
}
BITMAP bm;
CBitmap *pOldBm = memDC.SelectObject(&bitmap); //Store the previous bmp
HBITMAP hBmp = (HBITMAP)pOldBm->GetSafeHandle();
bitmap.GetObject(sizeof(bm), &bm);
CRect rect(0, 0, 10, 10);
pDC->StretchBlt(rect.left, rect.top, rect.Width() , rect.Height(), &memDC,
0,0, bm.bmWidth, bm.bmHeight,SRCCOPY);
//Distorted bitmap is displayed if rect size is smaller than bitmap size.
::SelectObject(memDC.m_hDC, hBmp);
bitmap.DeleteObject();
memDC.DeleteDC();
}