数学建模社区-数学中国

标题: 任意角度图片旋转 [打印本页]

作者: 韩冰    时间: 2005-1-26 12:47
标题: 任意角度图片旋转

void S_PicXZ(Graphics::TBitmap *Source,Graphics::TBitmap *NewPic,int angle)// & A; r" n: `4 z- I# }4 P { 3 h# ?7 D6 @5 |" c if(angle>180)angle=360-angle; 3 A4 C" Y/ W- V9 w' S/ Z6 [ if(angle<-180)angle=360+angle;

4 [5 [% [8 S6 T. l

float radians=(2*3.1416*angle)/360; & C% z9 m. u5 \: C' Cfloat cosine=(float)cos(radians); w$ k" H: v; j( v5 L2 ofloat sine=(float)sin(radians); ' [: ?" \) N- A( _! r+ e9 H) O% Z float Point1x=(-Source->Height*sine); 8 N9 Z* p3 J$ p; g% N) zfloat Point1y=(Source->Height*cosine); : O( f$ G5 d0 Y; @ float Point2x=(Source->Width*cosine-Source->Height*sine); 8 y9 k V3 _7 q4 J2 b6 y5 o float Point2y=(Source->Height*cosine+Source->Width*sine); 8 _5 Z( A' B$ B4 u% S, m float Point3x=(Source->Width*cosine); 5 Y6 C5 d' b7 O2 L, bfloat Point3y=(Source->Width*sine); {' m2 {. X- Y" G. g float minx=min((float)0,min(Point1x,min(Point2x,Point3x))); 2 e' J# O9 ~3 e$ n* z. l/ C. B0 Tfloat miny=min((float)0,min(Point1y,min(Point2y,Point3y))); * s& \% y$ G) U6 \1 a! E float maxx=max(Point1x,max(Point2x,Point3x)); * ?5 c, b) ~/ u% j \ float maxy=max(Point1y,max(Point2y,Point3y)); / ^$ o( A: t* }/ a5 Aint DestBitmapWidth,DestBitmapHeight; & z k( q f1 @3 A0 u" N: c if(angle>90&&angle<180) ( Y' n( E0 u3 `! p, C: f DestBitmapWidth=(int)ceil(-minx); 3 |* d/ I$ N0 }, ?& Y else 4 C+ a: C3 V! y, P5 e! zDestBitmapWidth=(int)ceil(maxx-minx);

& J! t, X1 `* } `) M G

if(angle>-180&&angle<-90) 6 j% N/ w2 R, f, d, ` DestBitmapHeight=(int)ceil(-miny); 7 N+ h) H! f. n% delse 5 v) ` b4 i9 U$ q4 g7 jDestBitmapHeight=(int)ceil(maxy-miny);

1 ] q6 W4 o) o

NewPic->Height=DestBitmapHeight; 5 Y2 E2 S! M, dNewPic->Width=DestBitmapWidth; 9 L: s% `/ f$ T$ G( |5 d* G0 ` for(int x=0;x<DestBitmapWidth;x++) 7 a# q( @' \& r% j5 a+ o{ ( Z4 F9 B3 K9 f+ V1 Q) W for(int y=0;y<DestBitmapHeight;y++){ # ~7 o% ^: C; E" v& w! l int SrcBitmapx=(int)((x+minx)*cosine+(y+miny)*sine); ; ~6 X9 P5 x: K# S# K0 }0 Fint SrcBitmapy=(int)((y+miny)*cosine-(x+minx)*sine); 9 m6 }% K9 Y' `) B0 `8 q/ C! ^# k7 i/ { if(SrcBitmapx>=0&&SrcBitmapx<Source->Width&&SrcBitmapy>=0&& , \% D; Q+ h5 m2 Q! x2 D% HSrcBitmapy<Source->Height) 7 s2 s! f4 v) E' H! r- y { ) e& Q) z6 s1 p- ^ NewPic->Canvas->ixels[x][y]= E3 ], I# j9 M' k5 R5 J# M Source->Canvas->ixels[SrcBitmapx][SrcBitmapy]; & D$ F; }% g4 c: N% c9 U } ( L# ?, B! R0 g4 |0 P$ `/ G4 H } 6 g, L! d$ m% g} 0 F" z1 ^: c+ ^; k( u}






欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5