关于逻辑坐标转化为设置坐标的使用
2008-08-25 09:51
281 查看
关于逻辑坐标转化为设置坐标的使用 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiMultimedia/html/delphi_2006121110211770.html
我原在一个大的区域作一个大图,现在显示时已小图,并在小的区域内居中显示
代码如下:
procedure TmlCadDataModule.DrawInRect(Canvas: TCanvas; ARect: TRect);
var
Rect : TRect;
HZoom, VZoom,myZoom: Integer;
fOrgPt : TPoint;
MemDC: HDC;
myWinExtSize : TSize;
myWinOrgSize : TPoint;
myViewExtSize : TSize;
myViewOrgSize : TPoint;
myMode : integer;
w,h : integer;
begin
//当前层
try
if not Assigned(fLayermanager) then Exit;
if not Assigned(fLayermanager.Layers[0]) then Exit;
fLayermanager.Layers[0].GetRect(Rect); //真实的大小
InflateRect(Rect,10,10);
// Rect 是大图时的区
HZoom := MulDiv(100, ARect.Right - ARect.Left, Rect.Right - Rect.Left);
VZoom := MulDiv(100, ARect.Bottom - ARect.Top, Rect.Bottom - Rect.Top);
if VZoom > HZoom then
myZoom := HZoom
else
myZoom := VZoom;
//取原点,关键在这,缩放后的原因是有变化的
w := ( Rect.Right - Rect.Left)*myZoom div 100; //缩放后的宽度
h := (Rect.Bottom - Rect.Top)*myZoom div 100; //缩放后的高度
fOrgPt := Point(ARect.Left + (ARect.Right-ARect.Left-w) div 2,
ARect.Top + (ARect.Bottom-ARect.Top-h) div 2);
myMode := GetMapMode(Canvas.Handle);
GetWindowExtEx(Canvas.Handle,myWinExtSize);
GetWindowOrgEx(Canvas.Handle,myWinOrgSize);
GetViewPortExtEx(Canvas.Handle,myViewExtSize);
GetViewPortOrgEx(Canvas.Handle,myViewOrgSize);
SetMapMode(Canvas.Handle, MM_ANISOTROPIC);
SetViewPortOrgEx(Canvas.Handle, -fOrgPt.X , -fOrgPt.Y ,nil);
SetWindowExtEx(Canvas.handle,100,100, nil);
SetViewPortExtEx(Canvas.Handle,myZoom,myZoom,nil);
fLayermanager.Layers[0].Draw(Canvas); //画内容
//恢复原来的值
SetMapMode(Canvas.Handle,myMode);
SetWindowOrgEx(Canvas.Handle,myWinOrgSize.X,myWinOrgSize.Y,nil);
SetViewportOrgEx(Canvas.Handle, myViewOrgSize.X, myViewOrgSize.Y, nil);
SetWindowExtEx(Canvas.Handle,myWinExtSize.cx,myWinExtSize.cy,nil);
SetViewportExtEx(Canvas.Handle,myViewExtSize.cx,myViewExtSize.cy,nil);
finally
end;
end;
有人回答吗
up
自己顶
自己顶
顶
帮up
我来帮顶!
你是不是要做预览?
自己顶
http://www.delphi2007.net/DelphiMultimedia/html/delphi_2006121110211770.html
我原在一个大的区域作一个大图,现在显示时已小图,并在小的区域内居中显示
代码如下:
procedure TmlCadDataModule.DrawInRect(Canvas: TCanvas; ARect: TRect);
var
Rect : TRect;
HZoom, VZoom,myZoom: Integer;
fOrgPt : TPoint;
MemDC: HDC;
myWinExtSize : TSize;
myWinOrgSize : TPoint;
myViewExtSize : TSize;
myViewOrgSize : TPoint;
myMode : integer;
w,h : integer;
begin
//当前层
try
if not Assigned(fLayermanager) then Exit;
if not Assigned(fLayermanager.Layers[0]) then Exit;
fLayermanager.Layers[0].GetRect(Rect); //真实的大小
InflateRect(Rect,10,10);
// Rect 是大图时的区
HZoom := MulDiv(100, ARect.Right - ARect.Left, Rect.Right - Rect.Left);
VZoom := MulDiv(100, ARect.Bottom - ARect.Top, Rect.Bottom - Rect.Top);
if VZoom > HZoom then
myZoom := HZoom
else
myZoom := VZoom;
//取原点,关键在这,缩放后的原因是有变化的
w := ( Rect.Right - Rect.Left)*myZoom div 100; //缩放后的宽度
h := (Rect.Bottom - Rect.Top)*myZoom div 100; //缩放后的高度
fOrgPt := Point(ARect.Left + (ARect.Right-ARect.Left-w) div 2,
ARect.Top + (ARect.Bottom-ARect.Top-h) div 2);
myMode := GetMapMode(Canvas.Handle);
GetWindowExtEx(Canvas.Handle,myWinExtSize);
GetWindowOrgEx(Canvas.Handle,myWinOrgSize);
GetViewPortExtEx(Canvas.Handle,myViewExtSize);
GetViewPortOrgEx(Canvas.Handle,myViewOrgSize);
SetMapMode(Canvas.Handle, MM_ANISOTROPIC);
SetViewPortOrgEx(Canvas.Handle, -fOrgPt.X , -fOrgPt.Y ,nil);
SetWindowExtEx(Canvas.handle,100,100, nil);
SetViewPortExtEx(Canvas.Handle,myZoom,myZoom,nil);
fLayermanager.Layers[0].Draw(Canvas); //画内容
//恢复原来的值
SetMapMode(Canvas.Handle,myMode);
SetWindowOrgEx(Canvas.Handle,myWinOrgSize.X,myWinOrgSize.Y,nil);
SetViewportOrgEx(Canvas.Handle, myViewOrgSize.X, myViewOrgSize.Y, nil);
SetWindowExtEx(Canvas.Handle,myWinExtSize.cx,myWinExtSize.cy,nil);
SetViewportExtEx(Canvas.Handle,myViewExtSize.cx,myViewExtSize.cy,nil);
finally
end;
end;
有人回答吗
up
自己顶
自己顶
顶
帮up
我来帮顶!
你是不是要做预览?
自己顶
相关文章推荐
- 关于VB.NET中动态设置控件坐标的使用心得休会
- 关于字符串中数字字符转化为数字 sscanf的使用以及strchr的使用
- 关于使用iOS scrollView进行图片浏览的坐标问题
- 关于使用Notepad++中编辑java文件关键字变色的设置
- 关于 QWidget无法使用stylesheet设置自身backgound-color(背景色)和border-image(背景图片) 的解决方法
- 关于cookie的设置使用注意事项(时间,路径)
- ArcEngine中使用对话框设置坐标参考系——ISpatialReferenceDialog2
- 关于bootstrap日期转化,bootstrap-editable的简单使用,bootstrap-fileinput的使用详解
- 关于设置 UITableView 的 tableHeaderView为使用了 SnapKit 约束的自定义 view 时出现的 BUG 的处理
- windows编程中关于设置映象模式,及坐标问题
- 关于Volley中JsonObjectRequest使用Post设置参数的问题
- 关于使用vue.js的模板渲染时出现一瞬间的设置的模板的解决方案
- 使用matplotlib的示例:调整字体-设置刻度、坐标、colormap和colorbar等
- [使用疑问] 关于 定位手表 设置 电子围栏功能实现疑问
- 关于vim的简单设置以及使用技巧
- 关于unity中使用Vuforia制作AR场景如何设置自动对焦的问题(全网独家)
- 一步步学习微软InfoPath2010和SP2010--第五章节--添加逻辑和规则到表单(3)--使用函数设置默认值
- 关于Windows下Apache使用虚拟主机(多域名多站点)的设置
- 关于使用LayoutParams清除设置以及DateFormat无法正确转换格式化日期的问题
- 关于iOS UITextView的一点使用心得,设置placeHolder效果