Print jpg picture

Have a table(MS SQL Server) of the information of employee. The field of photo are not store the data of photo. instead, store the filename of the photo, and the format of the photo is jpg too.
Now, I want to print the information of employees in the table. And load the photo from the file relevancy with the information by the ID of employee when print report. Is it possible? How to do it?

因为照片是jpg格式,且保存在文件夹中而不是保存在数据库中,数据库中只保存文件路径。怎么实现在报表预览时动态载入照片?
FastReport能不能实现?如果不能,有没有其它能实现的报表控制?
我用的是Delphi6.
;)

Comments

  • edited 4:13AM
    No response?
    Oh, I'm Chinese, My English is so pool.
    Can you read the minds?
  • edited 4:13AM
    Use the following code, but all the photo shown are same!
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      PV:=(frReport1.FindObject('Picture1') as TfrPictureView);
      frReport1.ShowReport;
    end;
    
    procedure TForm1.LoadPhoto;
    var
      S,FileName:String;
    begin
      S:= trim(ADOTable1.FieldByName('EmpID').AsString);
      {The FileName of the photo actual the ID of employee!}
      FileName:='C:\Documents and Settings\Administrator\My Documents\My Pictures\'
            + S +'.bmp';
      if FileExists(FileName) then
      begin
        PV.Picture.LoadFromFile(FileName);
      end;
    end;
    
    procedure TForm1.frReport1Progress(n: Integer);
    begin
      LoadPhoto;
    end;
    
  • edited 4:13AM
    The question are RESOLVED.
    But my English is so pool, so I doesn't translate it to English, Sorry!
    问题我自己解决了,道理很简单:
    主要是要在适当的时候载入照片。我原来是在报表的OnProgress事件中载入照片的,但这时的报表还算是模板,故预览时就会被固定为一个照片。现在把载入照片的代码放到报表的OnBefore事件中执行,显示结果就正确了,因为这时报表已经不是模板,而是预览后的报表!
    完整的代码如下:
    
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, FR_Class, jpeg, ExtCtrls, DBCtrls, DB, FR_DSet,
      FR_DBSet, ADODB;
    
    type
      TForm1 = class(TForm)
        Image1: TImage;
        frReport1: TfrReport;
        Button1: TButton;
        ADOConnection1: TADOConnection;
        ADOTable1: TADOTable;
        DataSource1: TDataSource;
        frDBDataSet1: TfrDBDataSet;
        ADOTable1EmpNo: TStringField;
        ADOTable1EmpName: TStringField;
        ADOTable1Photo: TBlobField;
        procedure Button1Click(Sender: TObject);
        procedure frReport1BeforePrint(Memo: TStringList; View: TfrView);
      private
        { Private declarations }
        PV:TfrPictureView;
        procedure LoadPhoto;
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      PV:=(frReport1.FindObject('Picture1') as TfrPictureView);
      frReport1.ShowReport;
    end;
    
    procedure TForm1.LoadPhoto;
    var
      S,FileName:String;
    begin
      S:= trim(ADOTable1.FieldByName('EmpNo').AsString);
      FileName:='C:\Documents and Settings\Administrator\My Documents\My Pictures\'
            + S +'.jpg';
      if FileExists(FileName) then
      begin
        PV.Picture.LoadFromFile(FileName);
      end;
    end;
    
    procedure TForm1.frReport1BeforePrint(Memo: TStringList; View: TfrView);
    begin
      LoadPhoto;
    end;
    
    end.
    

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.