就是背景得表盘移动
在网上找了个代码,有2个问题 一是 图片转动比较慢 转几次以后就卡死了 二是 转动以后 图片失真 并且有白得地方
void picturexz(Graphics::TBitmap *Source,Graphics::TBitmap *NewPic,int angle)//
{
if(angle>180){
angle=360-angle;
}
if(angle <-180){
angle=360+angle;
}
float radians=(2*3.1416*angle)/360;
float cosine=(float)cos(radians);
float sine=(float)sin(radians);
float Point1x=(Source->Height*sine);
float Point1y=(Source->Height*cosine);
float Point2x=(Source->Width*cosine-Source->Height*sine);
float Point2y=(Source->Height*cosine+Source->Width*sine);
float Point3x=(Source->Width*cosine);
float Point3y=(Source->Width*sine);
float minx=0,miny=0,maxx=0,maxy=0;
minx=Point2x<Point3x?Point2x:Point3x ;
minx=minx<Point1x?minx:Point1x;
minx=minx<0?minx:0;
miny=Point2y<Point3y?Point2y:Point3y ;
miny=miny<Point1y?miny:Point1y;
miny=miny<0?miny:0;
maxx=Point2x>Point3x?Point2x:Point3x ;
maxx=maxx>Point1x?maxx:Point1x;
maxx=maxx>0?maxx:0;
maxy=Point2y>Point3y?Point2y:Point3y ;
maxy=maxy>Point1y?maxy:Point1y;
maxy=maxy>0?maxy:0;
int DestBitmapWidth,DestBitmapHeight;
if(angle>90&&angle <180)
DestBitmapWidth=(int)ceil(-minx);
else
DestBitmapWidth=(int)ceil(maxx-minx);
if(angle>-180&&angle <-90)
DestBitmapHeight=(int)ceil(-miny);
else
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)
{
NewPic->Canvas->Pixels[x][y]=Source->Canvas->Pixels[SrcBitmapx][SrcBitmapy];
}
}
}
}
void __fastcall TForm1::Button3Click(TObject *Sender)
{
Graphics::TBitmap *pBmp=new Graphics::TBitmap();
picturexz(this->Image1->Picture->Bitmap,pBmp,10);
this->Image1->Picture->Bitmap=pBmp;
delete pBmp;
}