Ver Mensaje Individual
  #7  
Antiguo 26-06-2018
cloayza cloayza is offline
Miembro
 
Registrado: may 2003
Ubicación: San Pedro de la Paz, Chile
Posts: 913
Reputación: 22
cloayza Tiene un aura espectacularcloayza Tiene un aura espectacular
Estimado barakuda, si me permite le propongo otra opción...

Este método lo he usado cuando requiero mostrar imagenes en algunas aplicaciones...

Consiste en utilizar un TListview y TImageList...

Código Delphi [-]
unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls, Vcl.ImgList,
  Vcl.ExtCtrls, Vcl.Imaging.pngimage;

type
{Tipo de datos que usted puede definir para incorporar mas detalles a cada imagen}
  PInfoImg=^TInfoImg;
  TInfoImg=Record
    Title:string;
    Description:string;
    FileName:string;
    Url:string;
  End;

  TForm2 = class(TForm)
    ImageList: TImageList;
    ListView: TListView;
    Label1: TLabel;
    AddImagen: TButton;
    DeleteImagen: TButton;
    lblTitle: TLabel;
    lblDescription: TLabel;
    lblFilename: TLabel;
    lblUrl: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure ListViewSelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
    function CreateBitmap(Filename:string):TBitmap;
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

{Esta función crea un bitmap a partir de un nombre de archivo de imagen
}
function TForm2.CreateBitmap(Filename:string):TBitmap;
var
   picture:TPicture;
begin
     Try
        picture:=TPicture.Create;
        picture.LoadFromFile(Filename);

        Result := TBitmap.Create;
        Result.Assign(Picture.Graphic);

        picture.Free;
     except
        Result:=nil;
     End;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
     Listview.LargeImages:=ImageList;
     Listview.ViewStyle  :=vsIcon;
end;

procedure TForm2.AddImagenClick(Sender: TObject);
var
   FileName:string;
   imgInfo:PInfoImg;
begin
     if not PromptForFileName(Filename,'Png (*.png)|*.png|Bitmap (*.bmp)|*.bmp',
                                       '*.png','Agregar imagen','',false) then
        Exit;
     {Agrego la imagen a el ImageList...}
     ImageList.Add( CreateBitmap(FileName), nil);

     {Creo un puntero para almacenar mas información}
     imgInfo:=New(PInfoImg);
     imgInfo^.Title      :=Format('Imagen %d',[ListView.Items.Count]);
     imgInfo^.Description:=Format('Descripción Imagen %d',[ListView.Items.Count]);
     imgInfo^.FileName   :=Filename;
     imgInfo^.Url        :=Format('https://www.google.com?img=%s',[extractfilename(filename)]);

     with ListView.Items.Add do
     begin
          {Agrego un item y asigno el Title a Caption}
          Caption:=imgInfo^.Title;
          {En Data asigno el puntero con la informacion de la imagen}
          Data:=imgInfo;
          {Asigno el indice de la imagen}
          ImageIndex:=ImageList.Count-1;
     end;
end;

procedure TForm2.ListViewSelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
begin
     {Cada vez que pincho un item del Listview recupero los datos desde Item.Data}
     lblTitle.Caption      :=PInfoImg(Item.Data)^.Title;
     lblDescription.Caption:=PInfoImg(Item.Data)^.Description;
     lblFilename.Caption   :=PInfoImg(Item.Data)^.FileName;
     lblUrl.Caption        :=PInfoImg(Item.Data)^.Url;
end;
end.

La imagen adjunta muestra el resultado...


Espero le ayude...
Saludos cordiales
Responder Con Cita