首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

怎么水平翻转贴图

2012-12-19 
如何水平翻转贴图?如何水平翻转贴图?[最优解释]//上下翻转 BOOLUpDownReverse(LPBYTElpDIBits,longlWidth,

如何水平翻转贴图?
如何水平翻转贴图?
[最优解释]


//上下翻转 
BOOL   UpDownReverse(LPBYTE   lpDIBits,   long   lWidth,   long   lHeight,long   bitcount) 

long   i,j,k,l,temp; 
unsigned   char   *lpBits1,*lpBits2; 
k=lHeight/2;//将位图分成上下两个部分,然后上下对应的扫描行象素交换 
l=((lWidth*bitcount+31)> > 5) < <2;//四字节对齐 
for(j=0;j <k;j++) 
for(i=0;i <l;i++)         
{                 //指向位图上半部分的一行扫描行的象素 
lpBits1=lpDIBits+(lHeight-1-j)*l+i; 
//指向位图下半部分的一行扫描行的象素 
lpBits2=lpDIBits+j*l+i; 
//交换两部分象素 
temp=*lpBits1; 
*lpBits1=*lpBits2; 
*lpBits2=(unsigned   char)temp; 

return   TRUE; 
}


我记得GDI+有旋转函数的,我写过,我找找
[其他解释]
最笨的办法是你可以一个像素一个像素对调
[其他解释]
一、首先介绍Graphics的两个函数,
RotateTransform:将整个坐标系逆时针旋转一定角度
TranslateTransform:将整个坐标系偏移到某个位置
本例要实现的功能是在指定位置上旋转图片,首先需要将整个坐标系偏移到指定位置,在进行坐标系的旋转,在函数使用上应先旋转在偏移(与我们想象的相反),代码如下

myGraphics.RotateTransform(angle,MatrixOrderAppend);
myGraphics.TranslateTransform(pnt.x,pnt.y,MatrixOrderAppend);
//将图片画在pnt处,图片的中心点在rect1矩形的中心,DrawImage时坐标为图片在原坐标系的坐标减去坐标系的偏移
myGraphics.DrawImage(pImg,- rect1.Width(),- rect1.Height()/2,rect1.Width(), rect1.Height());
myGraphics.ResetTransform();    //将坐标系复位


二、还有一种方法可实现图形的旋转功能,那就是将所绘制的图形放入GraphicsPath中,然后设置图形变换矩阵,例子如下:


Graphics* g;
GraphicsPath myGraphicsPath(FillModeAlternate);
       int offsetrx=m_EllipseData.point1.x -origin.X;
       int offsetry=m_EllipseData.point1 .y -origin.Y;
RectF myRectangle(offsetrx,offsetry ,m_EllipseData.point2.x-m_EllipseData.point1.x,m_EllipseData.point2.y-m_EllipseData.point1 .y   );
 
              myGraphicsPath.AddEllipse (myRectangle);
              Matrix* myPathMatrix=new Matrix();
              myPathMatrix->Rotate(nRotateAngle, MatrixOrderAppend);
              myPathMatrix->Translate(origin.X,origin.Y,MatrixOrderAppend );
              myGraphicsPath.Transform(myPathMatrix);
              g->FillPath(&myBrush, &myGraphicsPath);




[其他解释]
。。。楼上的大哥,有适应DirectX的方法么?
[其他解释]
openCV 满足你的需求,十分简单。一个一个像素翻转也可以,最近学了openMP ,只要设计好了翻转速度很快

热点排行