Integer 部分拉伸时图像抖动 我使用C++ GDI、DealDigdiBs在DC上绘制图像。

Integer 部分拉伸时图像抖动 我使用C++ GDI、DealDigdiBs在DC上绘制图像。,integer,shake,stretchdibits,approximate,Integer,Shake,Stretchdibits,Approximate,因为原始图像很大,需要高质量的图像。 我使用HAFTONE模式,在DCzoom上绘制整个图像,图像似乎很耗时 所以我决定使用StretchDIBits部分绘制。 但是担架障碍物有一个严重的问题 我只能画一个整数区域的rect,宽度和高度,以及x,y的左上角都是整数 ::SetStretchBltMode(hdc, HALFTONE); ::StretchDIBits(hdc, realDrawRect.left, realDrawRect.top

因为原始图像很大,需要高质量的图像。 我使用HAFTONE模式,在DCzoom上绘制整个图像,图像似乎很耗时

所以我决定使用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,下次我想画21,20,61,60。 原始图像上没有相应的位置。所以我只能画一个近似于DC的矩形。现在问题发生了,图像正在抖动

我对那个问题很生气。
如何避免抖动?

如果抖动来自整数舍入,请尝试将其舍入到最接近的整数。看

否则,我建议您切换到GDI+,它更容易使用。使用GDI+可以绘制浮点精度的位图。见文件


我已经从GDI切换到GDI+,在几个MFC Active X项目中,这并不难。

< P>这是我在C++和C.使用扩展节时所遇到的一个正常问题,我们在调用伸缩功能之前,对图像的宽度和高度进行了校正:

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);