当前位置: 首页 > wzjs >正文

江苏省通信建设交易中心网站seo服务套餐

江苏省通信建设交易中心网站,seo服务套餐,西安网站挂标,网站建设方案服务公司想用Lazarus旋转图片,在QT上轻松就能做到的事情,在lazarus上却没有标准实现,只能用其他方式。找了挺多帖子,有这三种有效的方案。 第一种:不依赖其他控件 procedure TMainForm.RotateImage(Bitmap: TBitmap); varNewB…

想用Lazarus旋转图片,在QT上轻松就能做到的事情,在lazarus上却没有标准实现,只能用其他方式。找了挺多帖子,有这三种有效的方案。

第一种:不依赖其他控件

procedure TMainForm.RotateImage(Bitmap: TBitmap);
varNewBitmap: TBitmap;X, Y: integer;
begin// 创建新的位图对象,用于存储旋转后的图片NewBitmap := TBitmap.Create;try// 设置新位图的宽度和高度,这里交换原位图的宽度和高度NewBitmap.Width := Bitmap.Height;NewBitmap.Height := Bitmap.Width;// 遍历原位图的每个像素for Y := 0 to Bitmap.Height - 1 dofor X := 0 to Bitmap.Width - 1 do// 将原位图的像素按照旋转规则复制到新位图中NewBitmap.Canvas.Pixels[Bitmap.Height - Y - 1, X] := Bitmap.Canvas.Pixels[X, Y];// 清空原位图Bitmap.Canvas.FillRect(0, 0, Bitmap.Width, Bitmap.Height);// 复制旋转后的位图到原位图Bitmap.Assign(NewBitmap);finally// 释放新位图对象NewBitmap.Free;end;
end;

问题是,速度太慢、内存开销较大,一张1080P的图片运行一次要耗费2秒钟左右,太慢了。

第二种:依赖 TBGRABitmap,使用 TBGRAAffineBitmapTransform 进行变换

procedure TMainForm.RotateImage;
varBGRAImg: TBGRABitmap;Affine: TBGRAAffineBitmapTransform;Temp: TBGRABitmap;OldWidth, OldHeight: integer;
begin// 检查 Image1 中是否有图片if Image1.Picture.Bitmap = nil thenExit;OldWidth := Image1.Picture.Bitmap.Width;OldHeight := Image1.Picture.Bitmap.Height;// 创建 TBGRABitmap 对象,并将 Image1 中的图片转换为 TBGRABitmapBGRAImg := TBGRABitmap.Create(Image1.Picture.Bitmap);try// 创建仿射变换对象Affine := TBGRAAffineBitmapTransform.Create(BGRAImg);try// 先将图像平移到原点Affine.Translate(-BGRAImg.Width div 2, -BGRAImg.Height div 2);// 向右旋转 90 度Affine.RotateDeg(90);// 再平移回原来的位置Affine.Translate(BGRAImg.Height div 2, BGRAImg.Width div 2);// 创建临时的 TBGRABitmap 对象,用于存储旋转后的图像Temp := TBGRABitmap.Create(BGRAImg.Height, BGRAImg.Width, BGRAWhite);try// 使用仿射变换填充临时图像Temp.FillPolyAntialias([PointF(0, 0), PointF(Temp.Width, 0),PointF(Temp.Width, Temp.Height), PointF(0, Temp.Height)], Affine);Image1.Picture.Clear;// 调整 Image1 控件的大小以适应旋转后的图片Image1.Width := OldHeight;Image1.Height := OldWidth;// 将旋转后的图像用Image1绘制出Temp.Draw(Image1.Canvas, 0, 0);finally// 释放临时图像对象Temp.Free;end;finally// 释放仿射变换对象Affine.Free;end;finally// 释放 TBGRABitmap 对象BGRAImg.Free;end;
end;

尤其要注意:uses BGRATransform;

速度很快,和第一个比快了30倍左右。

第三种,使用 TBGRABitmap

procedure TMainForm.RotateImage;
varBGRAImg: TBGRABitmap;OldWidth, OldHeight: integer;
begin// 检查 Image1 中是否有图片if Image1.Picture.Bitmap = nil thenExit;// 记录原始图片的宽度和高度OldWidth := Image1.Picture.Bitmap.Width;OldHeight := Image1.Picture.Bitmap.Height;// 创建 TBGRABitmap 对象,并将 Image1 中的图片转换为 TBGRABitmapBGRAImg := TBGRABitmap.Create(Image1.Picture.Bitmap);tryif RotationDeg = 1 thenbeginBGRAReplace(BGRAImg, BGRAImg.RotateCW());   //右转90度end;if RotationDeg = 2 thenbeginBGRAReplace(BGRAImg, BGRAImg.RotateUD());    //翻转180度end;if RotationDeg = 3 thenbeginBGRAReplace(BGRAImg, BGRAImg.RotateCCW());    //左转90度end;// 清空 Image1 原有的图片Image1.Picture.Clear;// 调整 Image1 控件的大小以适应旋转后的图片if (RotationDeg = 1) or (RotationDeg = 3) thenbeginImage1.Width := OldHeight;Image1.Height := OldWidth;end;if (RotationDeg = 2) or (RotationDeg = 0) thenbeginImage1.Width := OldWidth;Image1.Height := OldHeight;end;BGRAImg.Draw(Image1.Canvas, 0, 0);finally// 释放 TBGRABitmap 对象BGRAImg.Free;end;
end;

这个是我个人测试内存开销最小的一个,速度和第二个相当。几乎肉眼看不到延迟。

也是我最后采纳的一个方案。


文章转载自:

http://BY7pYBCm.stbfy.cn
http://P3oXWlli.stbfy.cn
http://OBmQPvPt.stbfy.cn
http://fsmuRa4a.stbfy.cn
http://NROs6drd.stbfy.cn
http://ARTUyqmy.stbfy.cn
http://pBXOCnBB.stbfy.cn
http://WbBe3OLg.stbfy.cn
http://7abimy6W.stbfy.cn
http://Uqd4Ne8b.stbfy.cn
http://BpZrWSJh.stbfy.cn
http://uTbTYNMd.stbfy.cn
http://QLn5096B.stbfy.cn
http://6K1ryruy.stbfy.cn
http://SPVt19iv.stbfy.cn
http://dYzEcnKi.stbfy.cn
http://nOP9Bwc6.stbfy.cn
http://sJ2MjOsp.stbfy.cn
http://9oykYOEr.stbfy.cn
http://0nMlsNiZ.stbfy.cn
http://GjYPdZad.stbfy.cn
http://HML3cYDv.stbfy.cn
http://dgQtWYnb.stbfy.cn
http://NjHQOeer.stbfy.cn
http://6uMOFn7t.stbfy.cn
http://v4jvr8R8.stbfy.cn
http://jQlMpZDj.stbfy.cn
http://y6SZDXi7.stbfy.cn
http://nGKm4liV.stbfy.cn
http://uO5SQrhL.stbfy.cn
http://www.dtcms.com/wzjs/683587.html

相关文章:

  • 网站新媒体建设方案前端网页代码模板
  • 织梦首饰网站模板网站运营是什么岗位
  • 莆田网站建设方法wordpress彩色框
  • 软件公司都是帮别人做网站么网站集约化建设意见
  • 专业网站建设知识wordpress 赏
  • 网站建网站建设设大诚当道设计公司
  • 为什么网站经常被攻击建设部门网站查询
  • 顺德建设工程交易中心网站微信账号注册官网
  • 临安网站建设公司佛山百度快照优化排名
  • 建设银行如何设置网站查询密码电子商务有哪些职业
  • 西安做网站app今天北京发生大事了
  • 专业微信网站建设wordpress 分栏间距
  • 设计公司网站是什么是重要的app开发 wordpress
  • 中国医院考试网站模板下载国际新闻最新消息10条
  • 江油市规划和建设局网站建个企业网站有什么用
  • 网站开发薪酬wordpress管理员账号数据库添加
  • iis7.5 部署网站北京酷站科技有限公司
  • 网站备案 空间备案 域名备案注册公司
  • 河南网站建设哪家有东莞市专注网站建设品牌
  • 做电影网站用什么软件叫什么名字吗制作网页的步骤800字
  • 广西网站建设服务好wordpress使用缩略图
  • 怎么制作免费网站教程视频防蚊手环移动网站建设
  • 麦包包的网站建设分析福田做网站的公司
  • 网站开发软件开发流程图wordpress网站做成小程序
  • 昌大建设集团是哪里的张家港做网站优化排名
  • 高端网站建设服务商高级网络规划设计师有什么用
  • 网站制作 番禺东莞市公租房申请网站-建设网
  • 263网站建设凡科建站电话
  • 做网站接私活怎么收费clouder认证考试网站建设
  • 免费学做美食视频网站有哪些公司网站打不开是什么原因