|
假设对图片上任意点(x,y),绕一个坐标点(rx0,ry0)逆时针旋转RotaryAngle角度后的新的坐标设为(x', y'),有公式:
(x平移rx0,y平移ry0,角度a对应-RotaryAngle , 带入方程(7)、(8)后有: )
x'= (x - rx0)*cos(RotaryAngle) + (y - ry0)*sin(RotaryAngle) + rx0 ;
y'=-(x - rx0)*sin(RotaryAngle) + (y - ry0)*cos(RotaryAngle) + ry0 ;
那么,根据新的坐标点求源坐标点的公式为:
x=(x'- rx0)*cos(RotaryAngle) - (y'- ry0)*sin(RotaryAngle) + rx0 ;
y=(x'- rx0)*sin(RotaryAngle) + (y'- ry0)*cos(RotaryAngle) + ry0 ;
旋转的时候还可以顺便加入x轴和y轴的缩放和平移,而不影响速度,那么完整的公式为:
x=(x'- move_x-rx0)/ZoomX*cos(RotaryAngle) - (y'- move_y-ry0)/ZoomY*sin(RotaryAngle) + rx0 ;
y=(x'- move_x-rx0)/ZoomX*sin(RotaryAngle) + (y'- move_y-ry0)/ZoomY*cos(RotaryAngle) + ry0 ;
其中: RotaryAngle为逆时针旋转的角度;
ZoomX,ZoomY为x轴y轴的缩放系数(支持负的系数,相当于图像翻转);
move_x,move_y为x轴y轴的平移量;
一些颜色和图片的数据定义:
|
#define asm __asm
typedef unsigned char TUInt8; // [0..255] struct TARGB32 //32 bit color { TUInt8 b,g,r,a; //a is alpha };
struct TPicRegion //一块颜色数据区的描述,便于参数传递 { TARGB32* pdata; //颜色数据首地址 long byte_width; //一行数据的物理宽度(字节宽度); //abs(byte_width)有可能大于等于width*sizeof(TARGB32); long width; //像素宽度 long height; //像素高度 };
//那么访问一个点的函数可以写为: inline TARGB32& Pixels(const TPicRegion& pic,const long x,const long y) { return ( (TARGB32*)((TUInt8*)pic.pdata+pic.byte_width*y) )[x]; } //判断一个点是否在图片上 inline bool PixelsIsInPic(const TPicRegion& pic,const long x,const long y) { return ((x>=0)&&(x=0)&&(y} |
上一页 [1] [2] [3] [4] [5] [6] [7] 下一页
 【责编:Kittoy】
|