开发者

Import Images from File delphi

开发者 https://www.devze.com 2023-03-29 00:34 出处:网络
I\'m familiar with delphi scripting so I basically need a strong directi开发者_Python百科on to start from. I\'ve done importing images from files in other languages and it has been quite trivial, but

I'm familiar with delphi scripting so I basically need a strong directi开发者_Python百科on to start from. I've done importing images from files in other languages and it has been quite trivial, but I can find little documentation about this for delphi.

I need to be able to register a control event on a button that will open up a "choose folder/file" dialouge, and then import an image into an object that I can append to a List of some sort.

Anyone have any documentation on this?


Although your question is rather broad and "delphi scripting" sounds interesting here is an example that might get you started:

Project: Let the user select an image and display this image

This form contains a TButton, a TOpenPictureDialog and a simple TImage for displaying one image (sorry, no list of pictures in this example).

Import Images from File delphi

Part 1 ("register a control event on a button"):

Attach an OnClick event handler to the button by double clicking the button in the form designer. If your button's Name is btnOpenPicture then the auto-generated handler will have the name btnOpenPictureClick (see the following code). The code in this handler will be executed when the user clicks the button.

procedure TForm1.btnOpenPictureClick(Sender: TObject);
begin
  if OpenPictureDialog1.Execute(Self.Handle) then
    Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
end;

Part 2 ("'choose folder/file' dialouge") is represented by OpenPictureDialog1.Execute which opens a dialog where the user can choose a picture. The Execute command waits until the user closes the dialog and returns True if the user chose not to cancel the dialog but rather chose an image file (the filename is stored in OpenPictureDialog1.FileName).

Part 3 ("import an image into an object") would then be Image1.Picture.LoadFromFile which instructs the TImage component to load and display the file the user chose.

I cannot immediately name a component included in Delphi which could be used easily as a list for displaying images visually (that's your "append to a List of some sort"). I only know some third-party components which are not available for free, thus not good for quick experimenting.

Maybe this can be a base for asking more specific questions (as already encouraged by the commentators of your question). I already have one: "Is there a VCL component I could use for displaying a list of images?"


There are lots of articles and tutorials on how to do this. Code for loading images can be found in this Stackoverflow question; to complete your problem, you need a TButton and probably a TOpenPictureDialog.

0

精彩评论

暂无评论...
验证码 换一张
取 消