BCB做个仪表 背景图要动 图片转动 并且频率很高

任参果 2018-11-28 09:49:24



就是背景得表盘移动

在网上找了个代码,有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;
}

...全文
619 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
只旋转不能满足功能需求吧, 还有俯仰角度。
还是老老实实画吧 :
void draw( 坐标原点,水平旋转角度,俯仰角度 )
{ ...
}
chinayu2007 2019-02-25
  • 打赏
  • 举报
回复
用GDI+也可以旋转
draculamx 2018-11-29
  • 打赏
  • 举报
回复
要想效率高,直接使用win7中的Direct2D就行了,方便,直接在VCL中就可以用,不用去FMX
我不懂电脑 2018-11-28
  • 打赏
  • 举报
回复
引用 2 楼 zhiaisiying 的回复:
转动几次以后 卡死 是什么原因 也不是卡死 就是半天没反应 过几十秒就又好了


1.卡死一般是有资源漏洞造成的。
2.一般这种仪表盘都是用组态王做。
任参果 2018-11-28
  • 打赏
  • 举报
回复
转动几次以后 卡死 是什么原因 也不是卡死 就是半天没反应 过几十秒就又好了
ooolinux 2018-11-28
  • 打赏
  • 举报
回复
转动以后 图片失真
————
每次转动都用原始图片重新计算,而不是接着上次转动。
  • 打赏
  • 举报
回复
最简单的方法是准备一套各角度的图,根据需要贴上去。要实时旋转的话可以考虑用FMX,FMX框架中任意组件都支持旋转、3D坐标变换(2D组件也可以附在3D层上实现)。如果是左图这样的效果也可以实时绘制。

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧