中国程序员联盟 正在重新改版中ing 不便之处还请见谅 改版后将内容涉及java delphi .net php
 
  首页 | 数据库开发 | 网络通讯 | 多线程 | 多媒体开发 | 图像处理 | 程序人生 | 系统函数 | 控件开发 | Web服务
 
  当前位置:笨鱼delphi技术网>系统函数>文章内容

delphi Simple way to rotate region

来源:国外 关于:Nik Ozniev 发布时间:2007-07-03   [收藏] [推荐]
Problem/Question/Abstract:
Simple function returning rotated region. Pprocedure doing the same with source region.
Answer:
It's the simple function returning new region rotated to the angle that you want around the source region. Source region doesn't change.
The second procedure does the same with source region without creating new region.
I hope this will be useful.
Comments are provided along the code
function _RotateRgn(ARgn: HRGN; ADegree: Real): HRGN;
var
  wXFORM: XFORM; // transformation structure, see Windows API
  kRgnD: DWord; // count of RGNDATA structures in region
  RgnData: PRgnData; // pointer to region data
  Rt: TRect;
  kX, kY: Integer;
begin
  if (ARgn = 0) or (ADegree = 0) then
    Exit;
  // Get region's surrounding rectangular
  GetRgnBox(ARgn, Rt);
  // Move source region so that the centre of its surrounding rectangular
  // goes to the left top corner of a window
  kX := Rt.Left + (Rt.Right - Rt.Left) div 2;
  kY := Rt.Top + (Rt.Bottom - Rt.Top) div 2;
  OffsetRgn(ARgn, -kX, -kY);
  // Fill XFORM according to task (rotate region)
  FillChar(wXFORM, SizeOf(wXFORM), #0);
  wXFORM.eM11 := Cos(ADegree / 180 * pi);
  wXFORM.eM12 := -Sin(ADegree / 180 * pi);
  wXFORM.eM21 := -wXFORM.eM12;
  wXFORM.eM22 := wXFORM.eM11;
  // Prepare buffer to store region data
  kRgnD := GetRegionData(ARgn, 0, nil);
  GetMem(RgnData, SizeOf(RGNDATA) * kRgnD);
  // ..and fill the buffer with region's data
  GetRegionData(ARgn, kRgnD, RgnData);
  // ..move source region to its initial position
  OffsetRgn(ARgn, kX, kY);
  // Create output region using data in the buffer and transformation wXFORM
  Result := ExtCreateRegion(@wXFORM, kRgnD, RgnData^);
  // Move output region on a place of source region
  OffsetRgn(Result, kX, kY);
  FreeMem(RgnData);
end;
procedure _RotateRgnEx(var ARgn: HRGN; ADegree: Real);
var
  wXFORM: XFORM; // transformation structure, see Windows API
  kRgnD: DWord; // count of RGNDATA structures in region
  RgnData: PRgnData; // pointer to region data
  Rt: TRect;
  kX, kY: Integer;
begin
  if (ARgn = 0) or (ADegree = 0) then
    Exit;
  // Get region's surrounding rectangular
  GetRgnBox(ARgn, Rt);
  // Move source region so that the centre of its surrounding rectangular
  // goes to the left top corner of a window
  kX := Rt.Left + (Rt.Right - Rt.Left) div 2;
  kY := Rt.Top + (Rt.Bottom - Rt.Top) div 2;
  OffsetRgn(ARgn, -kX, -kY);
  // Fill XFORM according to task (rotate region)
  FillChar(wXFORM, SizeOf(wXFORM), #0);
  wXFORM.eM11 := Cos(ADegree / 180 * pi);
  wXFORM.eM12 := -Sin(ADegree / 180 * pi);
  wXFORM.eM21 := -wXFORM.eM12;
  wXFORM.eM22 := wXFORM.eM11;
  // Prepare buffer to store region data
  kRgnD := GetRegionData(ARgn, 0, nil);
  GetMem(RgnData, SizeOf(RGNDATA) * kRgnD);
  // ..and fill the buffer with region's data
  GetRegionData(ARgn, kRgnD, RgnData);
  // ..delete source region
  DeleteObject(ARgn);
  // Create new region using data in the buffer and transformation wXFORM
  ARgn := ExtCreateRegion(@wXFORM, kRgnD, RgnData^);
  // Move output region to the origin place
  OffsetRgn(ARgn, kX, kY);
  FreeMem(RgnData);
end;

[浏览: 次]   
上一篇:delphi 访问注册表   下一篇:delphi 显示任何形状的表单
[收藏] [推荐] [返回顶部] [打印本页] [关闭窗口]  
    评论加载中…
google adsense热点文章
·delphi Delphi中ShellExecute的妙用
·delphi 如何快速读取文本文件
·delphi 如何判断输入值是否中文
·delphi 在应用层截获键盘消息
·delphi delphi实现服务开启与关闭
·delphi 实时记录事件日志
·delphi 使MEMO自动滚动
·delphi 如何区分键盘两个Enter键
·delphi 切换界面的方法
·delphi 汉字输入法的编程及使用
·delphi Delphi程序输入法自动切换最简
·delphi 程序缩小为任务右下角的小图标
     delphi技术网 | firefox 下载 | Avant Browser下载 | dedecms 技术网 | drupal 爱好者 | php 技术网
  Copyright@www.delphichm.com,2006-2009.All Rights Reserved.
 
程序员联盟 | delphi Java .net|QQ:707102932