-
October 18th, 2018, 02:18 PM
#1
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
}
-
October 18th, 2018, 03:27 PM
#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
-
October 18th, 2018, 04:19 PM
#3
Re: Changing StretchDIBits() to GDI+ DrawImage creates scrolling problem when off scr
Originally Posted by philip_joa
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|