我使用C ++ GDI,的StretchDIBits到DC上绘制图像。
由于原始图像大,需要高品质。我用HAFTONE模式,借鉴DC整体的图像(放大图像)似乎时花费时间。
所以我决定绘制部分使用的StretchDIBits。但有关的StretchDIBits一个严重的问题。
我只能绘制整数RECT以整数的区域(宽度和高度,并且x的左上点,y是所有整数)
::SetStretchBltMode(hdc, HALFTONE);
::StretchDIBits(hdc,
realDrawRect.left,
realDrawRect.top,
realDrawRect.right - realDrawRect.left,
realDrawRect.bottom - realDrawRect.top,
left,
top,
width,
height,
pImageDIB,
pImageHead,
DIB_RGB_COLORS, SRCCOPY);
如果图像是21 * 21。我现在正在制定(5,5,7,7),以DC,在(20,20,60,60),下一次我WANN在(21,20,61,60)绘制。没有在原始图像中的相应位置。所以我只能得出一个近似矩形的DC。现在的问题发生时,图像晃动!
我很恼火有关问题。我怎样才能避免晃动?
如果摇晃来自四舍五入整数尝试舍入到最接近的整数。见this。
否则,我会建议您切换到GDI +是很容易的工作。在GDI +中,你可以绘制浮点精度的位图。见文档Graphics::DrawImage。
我从GDI切换到GDI +一对夫妇MFC活动-X项目,它是不难的。
这是当我在C ++中,以及在C#中使用的StretchDIBits我所面临的一个问题正常。为了克服这个问题,我们必须调用的StretchDIBits功能之前校正图像的宽度和高度的功能:
if (m_currentImage.Width % 2 != 0) // check for odd number
{
if (((m_currentImage.Width - 1) / 2) % 2 != 0)
m_currentImage = m_currentImage.Resize(m_currentImage.Width - 3, m_currentImage.Height - 2, Emgu.CV.CvEnum.Inter.Linear);
else
m_currentImage = m_currentImage.Resize(m_currentImage.Width - 1, m_currentImage.Height, Emgu.CV.CvEnum.Inter.Linear);
}
else if ((m_currentImage.Width / 2) % 2 != 0) // else check fraction of width is odd number
m_currentImage = m_currentImage.Resize(m_currentImage.Width - 2, m_currentImage.Height - 1, Emgu.CV.CvEnum.Inter.Linear);