Delphi 2010中单击缩略图时如何成像

发布于 2024-12-16 20:50:10 字数 201 浏览 0 评论 0原文

我是delphi的新手,我正在编写一个根本没有记录的代码。所以我们决定重做编码,而我是我们团队中唯一的人。没有人知道如何用 Delphi 编写代码。我的要求是这样的。

例如,我想为图像创建缩略图,让我们采用一个填充红色的矩形并将其显示在主窗体中。用户单击该缩略图,当用户单击显示区域中的任意位置时,该对象应该出现。有人可以给我一些提示或链接来继续此操作吗?这真的很有帮助。

I am new to delphi and I am working on a code which is not at all documented. So we decided to redo the coding and I am the only one in my team. Nobody knows how to code in Delphi. My requirement is something like this.

I want to create a thumbnail for an image for instance lets take a rectangle filled with red and display it in the main form. The user clicks this thumbnail and when user clicks anywhere in the display area this object should appear. Can someone give me some hints or link to proceed with this? It would be really helpful.

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

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

发布评论

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

评论(1

冰魂雪魄 2024-12-23 20:50:10

您需要在缩略图和主图像之间建立一些连接。
让我假设您将主图像存储在文件系统中。
如果所有缩略图的大小相同,则将它们存储在图像列表中是有意义的。
查看图像的常用控件是 ListView。

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, ComCtrls, ImgList;

type
  TForm9 = class(TForm)
    ImageList1: TImageList;
    ListView1: TListView;
    Image1: TImage;
    procedure ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    ListOfNames: TStringList;
  public

  end;

var
  Form9: TForm9;

implementation

{$R *.dfm}

procedure TForm9.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  ListOfNames.Free;
end;

procedure TForm9.FormCreate(Sender: TObject);
begin
  ListOfNames:= TStringList.Create;
  ListOfNames.Add('c:\pictures\filename1.bmp');
  ListOfNames.Add('c:\pictures\filename2.bmp');
end;

procedure TForm9.ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
var
  ImageIndex: integer;
  Filename: string;
begin
  ImageIndex:= Item.Index;
  Filename:= ListOfNames[ImageIndex];
  Image1.Picture.LoadFromFile(Filename);
end;

end.

这里是 DFM 文件的文本:

object Form9: TForm9
  Left = 0
  Top = 0
  Caption = 'Form9'
  ClientHeight = 468
  ClientWidth = 676
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnClose = FormClose
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Image1: TImage
    Left = 328
    Top = 64
    Width = 289
    Height = 318
    Stretch = True
  end
  object ListView1: TListView
    Left = 16
    Top = 232
    Width = 250
    Height = 150
    Columns = <>
    LargeImages = ImageList1
    TabOrder = 0
    OnSelectItem = ListView1SelectItem
  end
  object ImageList1: TImageList
    Left = 16
    Top = 192
  end
end

您需要将一些图像添加到 imagelist 这些图像将显示在 ListView 中。
单击列表视图中的项目将触发事件并在 TImage 中显示图像。

You would need to make some connection between the thumbnails and the main image.
Let me assume you have the main images stored in the filesystem.
If all your thumbnails are the same size, it makes sense to store them in a imagelist.
A common control to view Images is the ListView.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, ComCtrls, ImgList;

type
  TForm9 = class(TForm)
    ImageList1: TImageList;
    ListView1: TListView;
    Image1: TImage;
    procedure ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    ListOfNames: TStringList;
  public

  end;

var
  Form9: TForm9;

implementation

{$R *.dfm}

procedure TForm9.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  ListOfNames.Free;
end;

procedure TForm9.FormCreate(Sender: TObject);
begin
  ListOfNames:= TStringList.Create;
  ListOfNames.Add('c:\pictures\filename1.bmp');
  ListOfNames.Add('c:\pictures\filename2.bmp');
end;

procedure TForm9.ListView1SelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
var
  ImageIndex: integer;
  Filename: string;
begin
  ImageIndex:= Item.Index;
  Filename:= ListOfNames[ImageIndex];
  Image1.Picture.LoadFromFile(Filename);
end;

end.

Here the text for the DFM file:

object Form9: TForm9
  Left = 0
  Top = 0
  Caption = 'Form9'
  ClientHeight = 468
  ClientWidth = 676
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnClose = FormClose
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Image1: TImage
    Left = 328
    Top = 64
    Width = 289
    Height = 318
    Stretch = True
  end
  object ListView1: TListView
    Left = 16
    Top = 232
    Width = 250
    Height = 150
    Columns = <>
    LargeImages = ImageList1
    TabOrder = 0
    OnSelectItem = ListView1SelectItem
  end
  object ImageList1: TImageList
    Left = 16
    Top = 192
  end
end

You would need to add some images to the imagelist These will be shown in the ListView.
Clicking on an item in the listview will trigger the event and show the image in the TImage.

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