关于逻辑坐标转化为设置坐标的使用 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
我来帮顶!
你是不是要做预览?
自己顶