CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2018
    Posts
    2

    Changing StretchDIBits() to GDI+ DrawImage creates scrolling problem when off screen

    Hello, this is the first time I've ever asked for help in any forum. I'm new to GDI drawing, but not to Windows or c++. I changed the call StretchDIBits() to GDI+ DrawImage(). The original code with StretchDIBits() works fine, but the new code with DrawImage() has one problem; when the dialog is partially off the screen, scrolling in the direction opposite the screen side scrolls as it should a little ways, then scrolls the rest in all white.

    I've spent a lot of time on this, but I don't have enough experience with GDI and painting to the screen DC. I would greatly appreciate any ideas. Thank you in advance.

    void CView::OnPaint()
    {
    // standard paint routine
    CPaintDC dc(this);
    OnPrepareDC(&dc);
    OnDraw(&dc);
    }

    void CFaxView::OnDraw(CDC* pDC)
    {
    // Ignore OnPrepareDC settings!
    pDC->SetMapMode(MM_TEXT);
    pDC->SetViewportOrg(0, 0);
    pDC->SetWindowOrg(0, 0);

    int Index, Range;
    CViewPage* pViewPage;

    for (FindVisiblePages(Index, Range); Index <= Range; ++Index)
    {
    VERIFY((pViewPage = GetViewPage(Index)) != 0);
    pViewPage->Paint(this, pDC);
    }
    }

    void CViewPage::Paint(CWnd* pWnd, CDC* pDC)
    {
    // Clip subsequent drawing to the page area
    pDC->SaveDC();
    PreparePageDC(pDC);

    // Draw the page image
    CRect Rect(m_Origin, m_Size);
    if (pDC->RectVisible(Rect)) {
    PaintPageImage(pDC);
    }

    pDC->RestoreDC(-1);
    }

    BOOL CViewPage::PaintPageImage(CDC* pDC)
    {
    ASSERT(pDC);
    CRect ClipRect;
    pDC->GetClipBox(ClipRect);

    CRect ViewRect(m_Origin, m_Size);
    ClipRect &= ViewRect;
    if (ClipRect.IsRectEmpty())
    return TRUE;
    m_pImageFilter->PaintImage(pDC, m_Origin,ViewRect);
    }


    void CMonoImageFilter::PaintImage(CDC* pDC, CPoint Origin, const CRect& PaintRect)
    {
    ASSERT(pDC);
    ASSERT(m_pBitmapBuf);

    #if 1
    Graphics graphics(pDC->m_hDC);
    Bitmap bitmap((BITMAPINFO *)&m_BitmapInfo, m_pBitmapBuf);
    Rect gdiplusRect(Origin.x, Origin.y, PaintRect.Width(), PaintRect.Height());


    graphics.SetInterpolationMode(InterpolationMode::InterpolationModeHighQualityBicubic);
    graphics.SetPixelOffsetMode(PixelOffsetModeHalf);
    graphics.SetPageUnit(UnitPixel);
    // graphics.SetSmoothingMode(SmoothingModeHighQuality);
    graphics.SetSmoothingMode(SmoothingModeAntiAlias);

    ImageAttributes ImageAttributes;
    // ImageAttributes.SetWrapMode(WrapModeTileFlipXY, Color(), FALSE);
    ImageAttributes.SetWrapMode(WrapModeTileFlipXY);
    graphics.DrawImage(&bitmap, gdiplusRect, 0, 0, m_BitmapInfo.bmiHeader.biWidth, m_BitmapInfo.bmiHeader.biHeight, UnitPixel, &ImageAttributes);
    #else
    pDC->SetStretchBltMode(HALFTONE);
    SetBrushOrgEx(pDC->m_hDC,0,0,NULL);

    ::StretchDIBits(pDC->m_hDC,
    Origin.x,
    Origin.y,
    PaintRect.Width(),
    PaintRect.Height(),
    0,
    0,
    m_BitmapInfo.bmiHeader.biWidth,
    m_BitmapInfo.bmiHeader.biHeight,
    m_pBitmapBuf,
    (LPBITMAPINFO)&m_BitmapInfo,
    DIB_RGB_COLORS,
    SRCCOPY);
    #endif
    }

  2. #2
    Join Date
    Oct 2018
    Posts
    2

    Re: Changing StretchDIBits() to GDI+ DrawImage creates scrolling problem when off scr

    I've added the [code] for formatting like I should have done in the beginning. Sorry.

    Code:
    void CView::OnPaint()
    {
    	// standard paint routine
    	CPaintDC dc(this);
    	OnPrepareDC(&dc);
    	OnDraw(&dc);
    }
    
    void CFaxView::OnDraw(CDC* pDC)
    {
    	// Ignore OnPrepareDC settings!
    	pDC->SetMapMode(MM_TEXT);
    	pDC->SetViewportOrg(0, 0);
    	pDC->SetWindowOrg(0, 0);
    
    	int Index, Range;
    	CViewPage* pViewPage;
    
    	for (FindVisiblePages(Index, Range); Index <= Range; ++Index)
    	{
    	VERIFY((pViewPage = GetViewPage(Index)) != 0);
    	pViewPage->Paint(this, pDC);
    	}
    }
    
    void CViewPage::Paint(CWnd* pWnd, CDC* pDC)
    {
    	// Clip subsequent drawing to the page area
    	pDC->SaveDC();
    	PreparePageDC(pDC);
    
    	// Draw the page image
    	CRect Rect(m_Origin, m_Size);
    	if (pDC->RectVisible(Rect)) {
    		PaintPageImage(pDC);
    	}
    
    	pDC->RestoreDC(-1);
    }
    
    BOOL CViewPage::PaintPageImage(CDC* pDC)
    {
    	ASSERT(pDC);
    	CRect ClipRect;
    	pDC->GetClipBox(ClipRect);
    
    	CRect ViewRect(m_Origin, m_Size);
    	ClipRect &= ViewRect;
    	if (ClipRect.IsRectEmpty())
    		return TRUE;
    	m_pImageFilter->PaintImage(pDC, m_Origin,ViewRect);
    }
    
    
    void CMonoImageFilter::PaintImage(CDC* pDC, CPoint Origin, const CRect& PaintRect)
    {
    	ASSERT(pDC);
    	ASSERT(m_pBitmapBuf);
    
    #if 1 
    	Graphics graphics(pDC->m_hDC);
    	Bitmap bitmap((BITMAPINFO *)&m_BitmapInfo, m_pBitmapBuf);
    	Rect gdiplusRect(Origin.x, Origin.y, PaintRect.Width(), 	PaintRect.Height());
    
    
    	graphics.SetInterpolationMode(InterpolationMode::Interpolation	ModeHighQualityBicubic);
    	graphics.SetPixelOffsetMode(PixelOffsetModeHalf);
    	graphics.SetPageUnit(UnitPixel);
    	// graphics.SetSmoothingMode(SmoothingModeHighQuality); 
    	graphics.SetSmoothingMode(SmoothingModeAntiAlias);
    
    	ImageAttributes ImageAttributes;
    	// ImageAttributes.SetWrapMode(WrapModeTileFlipXY, Color(), 	FALSE);
    	ImageAttributes.SetWrapMode(WrapModeTileFlipXY);
    	graphics.DrawImage(&bitmap, gdiplusRect, 0, 0, 	m_BitmapInfo.bmiHeader.biWidth, 	 m_BitmapInfo.bmiHeader.biHeight, UnitPixel, &ImageAttributes);
    #else
    	pDC->SetStretchBltMode(HALFTONE);
    	SetBrushOrgEx(pDC->m_hDC,0,0,NULL);
    
    	::StretchDIBits(pDC->m_hDC, 
    	Origin.x, 
    	Origin.y, 
    	PaintRect.Width(), 
    	PaintRect.Height(), 
    	0, 
    	0, 
    	m_BitmapInfo.bmiHeader.biWidth,
    	m_BitmapInfo.bmiHeader.biHeight, 
    	m_pBitmapBuf, 
    	(LPBITMAPINFO)&m_BitmapInfo, 
    	DIB_RGB_COLORS, 
    	SRCCOPY);
    #endif
    }
    Last edited by VictorN; October 18th, 2018 at 04:15 PM. Reason: corrected CODE tags

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Changing StretchDIBits() to GDI+ DrawImage creates scrolling problem when off scr

    Quote Originally Posted by philip_joa View Post
    I've added the [code] for formatting like I should have done in the beginning. Sorry.
    It is good that you had added CODE tags!
    Note, however, that the ending tag must begin with the / (slash).

    And don't worry, I have corrected this issue.
    Victor Nijegorodov

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