CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Guest

    CDC::StretchBlt help

    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:raw(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();
    }


  2. #2
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: CDC::StretchBlt help

    I assume the distrotion you are seeing is due to the fact that you are trying to squash hundreds of scan lines into just 10. How should the bitmap decide what to leave and what to remove?

    The only thing you can do is adjust how StretchBlt() decides what to keep and what to discard. Check out the method CDC::SetStretchBltMode(). The STRETCH_ parameters are usually good for adjusting this behaviour.

    Does this help?


    --
    Jason Teagle
    [email protected]

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured