void S_PicXZ(Graphics::TBitmap *Source,Graphics::TBitmap *NewPic,int angle)// 5 f4 W8 F! f& {6 A8 {3 E { if(angle>180)angle=360-angle; if(angle<-180)angle=360+angle;
- ^" F+ {# |" g, jfloat radians=(2*3.1416*angle)/360; float cosine=(float)cos(radians); float sine=(float)sin(radians); " N* @, @) i1 U* `% t float Point1x=(-Source->Height*sine); + s# Z% y, e2 C float Point1y=(Source->Height*cosine); float Point2x=(Source->Width*cosine-Source->Height*sine); % s% d# n! W9 I4 W& F5 L float Point2y=(Source->Height*cosine+Source->Width*sine); float Point3x=(Source->Width*cosine); % r8 O! o$ [& U' O float Point3y=(Source->Width*sine); float minx=min((float)0,min(Point1x,min(Point2x,Point3x))); float miny=min((float)0,min(Point1y,min(Point2y,Point3y))); float maxx=max(Point1x,max(Point2x,Point3x)); float maxy=max(Point1y,max(Point2y,Point3y)); f1 Y1 W. M, R7 Y- D int DestBitmapWidth,DestBitmapHeight; if(angle>90&&angle<180) DestBitmapWidth=(int)ceil(-minx); ( N6 H" l7 E3 W* H2 ` else $ E( f* p/ d" r j0 N2 w+ z DestBitmapWidth=(int)ceil(maxx-minx);
if(angle>-180&&angle<-90) 2 p6 v3 \, J. E& B2 b; }' x3 g DestBitmapHeight=(int)ceil(-miny); else ' N, K* J0 j3 E' p DestBitmapHeight=(int)ceil(maxy-miny);
NewPic->Height=DestBitmapHeight;
NewPic->Width=DestBitmapWidth;
for(int x=0;x<DestBitmapWidth;x++)
{
for(int y=0;y<DestBitmapHeight;y++){
int SrcBitmapx=(int)((x+minx)*cosine+(y+miny)*sine);
int SrcBitmapy=(int)((y+miny)*cosine-(x+minx)*sine);
if(SrcBitmapx>=0&&SrcBitmapx<Source->Width&&SrcBitmapy>=0&&
SrcBitmapy<Source->Height) / Q# v- F& `4 `- ~0 N4 b9 y
{ 4 x& g. h+ n1 v8 s; Y, L
NewPic->Canvas->
ixels[x][y]=
Source->Canvas->
ixels[SrcBitmapx][SrcBitmapy]; 6 f9 b' Z! Q/ J0 S# \
} N6 Y8 F% A' |2 M9 T) R# t3 f3 S
} % E+ U9 |1 a% k
} % d7 `) Q* {5 _
}
| 欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) | Powered by Discuz! X2.5 |