克服 TImage Control 限制

发布于 2024-12-22 22:28:52 字数 617 浏览 3 评论 0原文

我在 Delphi 4 中的 TScrollBox 控件内使用 TImage 控件。这里我通过相应增加高度来填充 TImage 控件中的数据。

我的功能基于 mousedown 事件,其中我使用 X、Y 参数来执行一些验证并突出显示该记录。

现在的问题是 X、Y 是整数类型参数,它们返回 -32768 到 32767 之间的值。当我的记录超出 32767 高度时,我遇到问题。 Mousedown 事件返回 Y 值,因为负面原因导致我的功能出现问题。

有 2 种可能的方法可以解决此问题,

  1. 解决此问题的任何解决方法。

  2. 使用 Delphi 4 的另一个内置组件作为替代。

我知道一种肮脏的方法(可能这也不正确,但目前有效),如下所述,但我正在寻找更好的解决方案。

if Y < 0 then 
begin
      Y := Y + 65536;
end
else
begin
     if ScrollBox1.VertScrollBar.Position > 32767 then
        Y := Y + 65536;
end;

请建议更好的解决方案来解决这个问题

I am using TImage control inside TScrollBox control in Delphi 4. Here i am populating data in TImage control by increasing the height accordingly.

My functionality is based on the mousedown event where i am using X, Y parameters to do some validations with highlighting that record.

Now issue here is X, Y are integer type parameters, and they return values in between -32768 to 32767. I am facing issues when my records are going beyond 32767 height. Mousedown event is returning Y value as negative causes issues with my functionality.

There are 2 possible ways to resolve this issue,

  1. Any workaround to fix this issue.

  2. Using another inbuilt component of Delphi 4 as an replacement.

I know one dirty approach (may be this is also not correct but working as of now) as mentioned below, but i am looking for better solution.

if Y < 0 then 
begin
      Y := Y + 65536;
end
else
begin
     if ScrollBox1.VertScrollBar.Position > 32767 then
        Y := Y + 65536;
end;

Please advice a better solution to this problem

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

装迷糊 2024-12-29 22:28:52

鼠标坐标通常源自 WMMouseMove 消息,该消息的记录定义如下:

type TLMMouse = record
  Msg: Cardinal;
  Keys: PtrInt;
  case Integer of
    0: (XPos: SmallInt;
        YPos: SmallInt;);
    1: (Pos: TSmallPoint;);
    2: (Dummy: LPARAM;
        Result: LRESULT;);
end;

由于鼠标消息将坐标打包在 2 个小整数中,因此无法解决您的问题。

请注意,GetCursorPos 提供带有两个 Int32 的 TPoint 记录,但这不是您的控件使用的函数,因此您不会从中受益。

The mouse coordinates are usually derived from a WMMouseMove message, the record definition for this message is as follows:

type TLMMouse = record
  Msg: Cardinal;
  Keys: PtrInt;
  case Integer of
    0: (XPos: SmallInt;
        YPos: SmallInt;);
    1: (Pos: TSmallPoint;);
    2: (Dummy: LPARAM;
        Result: LRESULT;);
end;

Because the Mouse Messages pack the coordinates in 2 smallints, there is no way around your issue.

Note that GetCursorPos gives a TPoint record with two Int32's, however this is not the function that your control uses, so you don't benefit from this.

紙鸢 2024-12-29 22:28:52

还有第三种方法可以解决。停止使用 Scrollbox,并使用自己的滚动条句柄编写自己的控件,该控件可以在您指定的 X、Y 坐标处呈现图像的一部分。事实上,您可以通过向您编写的任何简单的基于 TControl 的组件添加滚动条来实现此目的;如果你坚持使用 Delphi 中的内置控件,你实际上会做一些有点可笑的事情。编写您自己的控件可以通过几行代码完成,如果您不想使用第三方控件,那么这是正确的答案。

第二种选择,事实上,99% 的 Delphi 开发人员都会选择的解决方案,是切换到已经具有此功能的第三方图像查看器控件。显然,重新发明轮子是没有意义的。您的问题似乎规定您不能添加第三方控件。

从性能角度来看,Scrollboxes + TImage 是一个糟糕的解决方案,特别是当您必须将巨大的图像完全加载到 GDI 内存中以包含图片时。令我惊讶的是,32K 像素高 x 1000+像素高的图像甚至可以毫无严重问题地加载到内存中。您当前的想法不仅受到 Scrollbox 的限制(回答这个问题的其他人很好地解释了),而且还受到 GDI 图像处理能力的限制,这(对于非常大的图像)并不完全理想。

不管你喜欢与否,要么自己写,要么使用delphi 的图像查看器。在链接页面上,Ahmoy Law 的 Image Visualizer for Delphi v.1.00.00 对我来说看起来不错。

There is a third way to solve it. Stop using a Scrollbox, and write your own control with its own scroll bar handles, that can render part of an image, at X,Y co-ordinates specified by you. You could in fact do this by adding scrollbars to any simple TControl-based component written by you; if you insist on using a built-in control in Delphi you will in fact be doing something faintly rediculous. Writing your own control can be done in a few lines of code, and is the right answer if you do not wish to use third party controls.

The second alternative, and in fact, the solution that 99% of Delphi developers would pick, is to switch to a third-party image viewer control that will already have this functionality. Obviously, there is no point reinventing the wheel. Your question seems to stipulate that you can't add a third party control.

Scrollboxes + TImage are a terrible solution from a performance point of view, especially when you must load an enormous image entirely into GDI memory to contain the picture. I am surprised that a 32K-pixel high by 1000+pixel high image would even load into Memory without serious problems. Your current idea is not only limited by the Scrollbox's limitations (explained well by the other person who answered this question) it is limited by GDI's image processing capabilities, which are (for very large images) not exactly ideal.

Whether you like it or not, either write your own, or use an image viewer for delphi. On the linked page, the Image Visualizer for Delphi v.1.00.00 by Ahmoy Law looks good to me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文