在画布上用十进制值绘制图像 [英] Draw image in canvas with decimal values

查看:74
本文介绍了在画布上用十进制值绘制图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制源自X,Y值列表的图像,这些值表示直线的起点和终点。它们以英寸为单位,因此它们当前的格式为小数。

I am trying to draw an image originating from a list of X,Y values that represent the start and stop points of a line. They are in inches, so they are currently formatted in to decimals.

我遇到的问题是图形。 MoveTo LineTo 命令需要一个整数而不是双精度数。如果我使用 Round(float)数学运算,则会看到以下输出。四舍五入的结果在相同的起点和终点,因此什么也没画。

The problem I am having is with the drawing. The MoveTo and LineTo commands require an integer not a double. If I use the Round(float) math operation, you see the output below. The rounding results in the same start and stop point, so nothing is drawn.

如何从十进制X,Y点列表中绘制形状?

How can I draw my shape from a list of decimal X,Y points?

调试输入值(十进制)的代码:

LineStartVal: -88.988857, 36.265838
LineEndVal: -89.094923, 36.371904
LineStartVal: -89.094923, 36.371904
LineEndVal: -95.000423, 36.371904
LineStartVal: -95.000423, 36.371904
LineEndVal: -95.000423, 32.828604
LineStartVal: -95.000423, 32.828604
LineEndVal: -99.134273, 32.828604

舍入后输出点的调试代码:

MoveTo: -89, 36
LineTo: -89, 36
MoveTo: -89, 36
LineTo: -95, 36
MoveTo: -95, 36
LineTo: -95, 33
MoveTo: -95, 33
LineTo: -99, 33

绘图代码段:

//Function used to to get start and stop points
LSNLineObj.GetEndPoints(X1,Y1,X2,Y2);


//OutputMemo.Text := OutputMemo.Text + #13#10 + 'LineStartVal: ' + FloatToStrF(X1, ffGeneral, 8, 4) + ', ' + FloatToStrF(Y1, ffGeneral, 8, 4);
//OutputMemo.Text := OutputMemo.Text + #13#10 + 'LineEndVal: ' + FloatToStrF(X2, ffGeneral, 8, 4) + ', ' + FloatToStrF(Y2, ffGeneral, 8, 4);

X1int := Round(X1); X2int := Round(X2);
Y1int := Round(Y1); Y2int := Round(Y2);

PartImage.Canvas.MoveTo(X1int,X2int);

OutputMemo.Text := OutputMemo.Text + #13#10 + 'MoveTo: ' + IntToStr(X1int) + ', ' + IntToStr(Y1int);

PartImage.Canvas.LineTo(X2int,Y2int);

OutputMemo.Text := OutputMemo.Text + #13#10 + 'LineTo: ' + IntToStr(X2int) + ', ' + IntToStr(Y2int);


推荐答案

您有两个坐标系:首先,您有坐标系坐标为 -88.988857、36.265838 的逻辑系统。其次,您有屏幕。您需要在这两者之间进行转换。您应该编写函数

You have two coordinate systems: first, you have your 'logical' system with coordinates like -88.988857, 36.265838. Second, you have the screen. You need to convert between these two. You should write functions

function LogToScreen(LogPoint: TRealVector): TPoint;
function ScreenToLog(Point: TPoint): TRealVector;

其中 TRealVector 是包含两个双精度值的记录。编写这两个函数仅需要小学数学。

where TRealVector is a record containing two doubles. Writing these two functions requires only elementary-school mathematics.

例如,您可以让屏幕上的矩形 0..800 0..600 对应于逻辑值 -110 ..- 80 30..40

For instance, you could let the on-screen rectangle 0..800 and 0..600 correspond to logical values -110..-80 and 30..40.

提示:使用上述值,

function LogToScreen(LogPoint: TRealVector): TPoint;
begin
  result.X := round(800 * (LogPoint.X - (-110)) / ((-80) - (-110)));
  result.Y := round(600 * (LogPoint.Y - 30) / (40 - 30)); // or rev. orientation
end;

这篇关于在画布上用十进制值绘制图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆