Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   savedialog para exportar listview a bmp? (https://www.clubdelphi.com/foros/showthread.php?t=81556)

BioStudio 24-11-2012 05:56:47

savedialog para exportar listview a bmp?
 
estuve probando de muchas formas pero únicamente logre que se genere el archivo pero no obtengo nada dentro.. :(:(

Código Delphi [-]
procedure TForm2.Button2Click(Sender: TObject);
var
  bmp: TBitmap;
  i : Integer;
  saveDialog : TSaveDialog;
begin
  saveDialog := TSaveDialog.Create(self);
  saveDialog.Title := 'Respaldo de Archivo en Formato BMP';
  saveDialog.InitialDir := GetCurrentDir;
  saveDialog.Filter := 'Texto (delimitado por tabulaciones) (*.bmp)|*.bmp';
  saveDialog.DefaultExt := 'bmp';
  saveDialog.FilterIndex := 1;

  if saveDialog.Execute then
  begin
     with TBitmap.Create do
     try
    Width := umain.Form1.ListView1.Width;
    Height := umain.Form1.ListView1.Height;
    Canvas.Lock;
    try
      umain.Form1.ListView1.Perform(WM_PRINT, Canvas.Handle, PRF_CHILDREN or PRF_CLIENT or PRF_NONCLIENT);
    finally
      Canvas.UnLock;
      SaveToFile(SaveDialog.FileName)
      //SaveToFile(SaveDialog.FileName);
    end;
  finally
    bmp.Free
  end;
           //try
             // SaveToFile(SaveDialog.FileName);
           //except
             // ShowMessage('Error en la Generación del Archivo BMP');
           //end;
   //  finally
     //   free;
     //end;
  end;

  saveDialog.Free;
end;

ecfisa 24-11-2012 08:14:58

Hola BioStudio.

Probé el código que pusiste y quitando la sentencia: bmp.Free donde liberabas una instancia no creada funciona bién.

Lo único que omití en la prueba fue: umain.Form1, ya que la hice sobre el propio Form1.
Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
var
  bmp: TBitmap;
  i : Integer;
begin
  with TSaveDialog.Create(self) do
  try
    Title := 'Respaldo de Archivo en Formato BMP';
    InitialDir := GetCurrentDir;
    Filter := 'Texto (delimitado por tabulaciones) (*.bmp)|*.bmp';
    DefaultExt := 'bmp';
    FilterIndex := 1;
    if Execute then
    begin
      with TBitmap.Create do
      try
        Width := ListView1.Width;
        Height := ListView1.Height;
        Canvas.Lock;
        try
          ListView1.Perform(WM_PRINT, Canvas.Handle,
            PRF_CHILDREN or PRF_CLIENT or PRF_NONCLIENT);
        finally
          Canvas.UnLock;
          SaveToFile(FileName)
        end
      finally
        Free
      end
    end
  finally
    Free
  end
end;

Archivo resultante:


Saludos.


La franja horaria es GMT +2. Ahora son las 20:25:33.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi