有人做过图像变换吗? 对一个24位图像进行平移、缩放、旋转三种操作即可, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Bitblt / StretchBlt即可旋转的稍微麻烦一点,但例子也很多 以前写的,通用部分。使用时,你得自己将相应的变量定义并正确赋值才能用。旋转: if (nFlag == RO_CLOCKWISE) // 顺时针旋转 { if (nBitCount == 24) { RGBTRIPLE *pSrc, *pDst; for (j = 0; j < ndstHeight; j++) { pSrc = (RGBTRIPLE *)psrcBits + j; pDst = (RGBTRIPLE *)(pdesBits + ndesLineBytes * (ndstHeight-1-j)); for (i = 0; i < ndstWidth; i++) pDst[i] = *(RGBTRIPLE *)((PUCHAR)pSrc + nsrcLineBytes * i); } } } else // 逆时针旋转 { if (nBitCount == 24) { RGBTRIPLE *pSrc, *pDst; for(j = 0; j < ndstHeight; j++) { pSrc = (RGBTRIPLE *)(psrcBits + nsrcLineBytes * (ndstWidth-1)) + j; pDst = (RGBTRIPLE *)(pdesBits + ndesLineBytes * j); for(i = 0; i < ndstWidth; i++) pDst[i] = *(RGBTRIPLE *)((PUCHAR)pSrc - nsrcLineBytes * i); } } }平移实在没什么好说的。我也没写。 使用GDI+或者使用SetWorldTransform 旋转角度: POINT centerPt = CPoint(100, 100); // 旋转中心点 int nGraphicsMode = SetGraphicsMode(hDc, GM_ADVANCED); XFORM xform; if ( m_iAngle != 0 ) { double fangle = (double)m_iAngle / 180. * 3.1415926; // m_iAngle 角度 xform.eM11 = (float)cos(fangle); xform.eM12 = (float)sin(fangle); xform.eM21 = (float)-sin(fangle); xform.eM22 = (float)cos(fangle); xform.eDx = (float)(centerPt.x - cos(fangle)*centerPt.x + sin(fangle)*centerPt.y); xform.eDy = (float)(centerPt.y - cos(fangle)*centerPt.y - sin(fangle)*centerPt.x); SetWorldTransform(hDc, &xform); }在这里画图,就是旋转的了. ::Rectangle(hDc, centerPt.x - 20, centerPt.y - 30, centerPt.x + 20, centerPt.y + 30 ); CTreeCtrl设为子树的问题,求助。 怎么用win32在指定点画bitmap或者png,注意不是MFC哦。 好迷惑呀!!! CSocket不能跨线程,谁知道是什么原因吗? 求助 怎样用程序来判断DirectX窗口和普通窗口的不同呢 usb readfile无数据? 熟悉COM的高手帮帮我! 很简单,你不一定知道哦 小丸子你的意思是不是说,一开始就申请double[100][100],保证一百足够大,然后只用到其中的比如说50为止,其他就放空? 怎么改变对话框的颜色 基于 MFC7 的控制台程序主线程里不能调用 PeekMessage ?
旋转的稍微麻烦一点,但例子也很多
if (nFlag == RO_CLOCKWISE) // 顺时针旋转
{
if (nBitCount == 24)
{
RGBTRIPLE *pSrc, *pDst;
for (j = 0; j < ndstHeight; j++)
{
pSrc = (RGBTRIPLE *)psrcBits + j;
pDst = (RGBTRIPLE *)(pdesBits + ndesLineBytes * (ndstHeight-1-j));
for (i = 0; i < ndstWidth; i++)
pDst[i] = *(RGBTRIPLE *)((PUCHAR)pSrc + nsrcLineBytes * i);
}
}
}
else // 逆时针旋转
{
if (nBitCount == 24)
{
RGBTRIPLE *pSrc, *pDst;
for(j = 0; j < ndstHeight; j++)
{
pSrc = (RGBTRIPLE *)(psrcBits + nsrcLineBytes * (ndstWidth-1)) + j;
pDst = (RGBTRIPLE *)(pdesBits + ndesLineBytes * j);
for(i = 0; i < ndstWidth; i++)
pDst[i] = *(RGBTRIPLE *)((PUCHAR)pSrc - nsrcLineBytes * i);
}
}
}平移实在没什么好说的。我也没写。
或者使用SetWorldTransform
POINT centerPt = CPoint(100, 100); // 旋转中心点 int nGraphicsMode = SetGraphicsMode(hDc, GM_ADVANCED);
XFORM xform;
if ( m_iAngle != 0 )
{
double fangle = (double)m_iAngle / 180. * 3.1415926; // m_iAngle 角度
xform.eM11 = (float)cos(fangle);
xform.eM12 = (float)sin(fangle);
xform.eM21 = (float)-sin(fangle);
xform.eM22 = (float)cos(fangle);
xform.eDx = (float)(centerPt.x - cos(fangle)*centerPt.x + sin(fangle)*centerPt.y);
xform.eDy = (float)(centerPt.y - cos(fangle)*centerPt.y - sin(fangle)*centerPt.x); SetWorldTransform(hDc, &xform);
}
在这里画图,就是旋转的了. ::Rectangle(hDc,
centerPt.x - 20,
centerPt.y - 30,
centerPt.x + 20,
centerPt.y + 30 );