Einzelnen Beitrag anzeigen

Benutzerbild von LDericher
LDericher

Registriert seit: 29. Jan 2007
Ort: Erkelenz
224 Beiträge
 
Delphi 7 Enterprise
 
#3

Re: Koordinaten umrechnen, nur wie?

  Alt 15. Dez 2008, 16:11
Für die Allgemeinheit, hier die Lösung des Problems:

Delphi-Quellcode:
function PosOnPicture(Display: TImage): TPoint;
var
  IMGRelation,
  DisplayRelation,
  Scale:Extended;
  OffsX,
  OffsY:integer;
  MPos:TPoint;
  procedure BorderIt(var Input:integer; MaxBorder, MinBorder:integer);
  begin
  if(Input>MaxBorder)
    then Input:=MaxBorder
  else if(Input<MinBorder)
    then Input:=MinBorder;
  end;
begin
IMGRelation:=Display.Picture.Width/Display.Picture.Height;
DisplayRelation:=Display.Width/Display.Height;
if(DisplayRelation>IMGRelation)then
  begin
  Scale:=(Display.Height/Display.Picture.Height);
  OffsX:=(Display.Width div 2)-(round(Scale*Display.Picture.Width) div 2);
  OffsY:=0;
  end else
  begin
  Scale:=(Display.Width/Display.Picture.Width);
  OffsX:=0;
  OffsY:=(Display.Height div 2)-(round(Scale*Display.Picture.Height) div 2);
  end;
GetCursorPos(MPos);
MPos:=Display.ScreenToClient(MPos);
MPos.X:=MPos.X-OffsX;
MPos.Y:=MPos.Y-OffsY;
Result.X:=round(MPos.X/Scale);
Result.Y:=round(MPos.Y/Scale);
BorderIt(Result.X, Display.Picture.Width, 0);
BorderIt(Result.Y, Display.Picture.Height, 0);
end;
  Mit Zitat antworten Zitat