锐浪报表 Grid++Report 图像打印

    Grid++Report报表,打印图像在模板文件中,使用PictureBox控件。

    一、关于图像的来源

     1、图像格式:

      一是指定目录中的以图像文件。二是保存在数据库中的二进制图像数据。

     保存在数据库中的图像文件,又有二种方式,一是整个图像存入数据库某个字段中,二是仅在数据库字段中,保存该图像在全路径文件名,或指定目录的文件名。

     2、图像的读取:

     (1)在模板中直接存储二进制图像数据,即在设计报表时指定“图像”属性。
     (2)显示图像集合中的图像,由“图像序号”属性指定。
     (3)显示示系统图像,由“图像序号”属性指定。
     (4)显示磁盘图像文件或WEB上的URL图像,由“图像文件”属性指定。
     (5)图像来自记录集字段,由“数据字段”属性指定。

     3、字段的类型:
    (1)字段为二进制类型时,则从此二进制字段直接载入图像数据。
    (2)字段为整数类型时,则按此字段值载入对应图像集合图像或系统图像。
    (3)字段为字符类型时,且此字段中存储了图像的路径文件名或URL,则从对应位置加载图像。
    (4)图像可以用 IGRPicture 接口的方法载入,比较复杂一点。
    (5)明细网格中的图像用程序代码载入时,必须在对应事件中执行。

     二、打印图像的控件

     使用PictureBox控件,

    1、在报表头ReportHeader和报表尾ReportFooter中,加入PictureBox控件,设置好位置及大小后,GridppReport1FetchRecord事件中。代码:

if FieldByName('跌倒').AsBoolean then
    begin
      P1:=P1+1;
      sVCLName:='PictureBox'+InttoStr(P1);
      sFileName:=PhotoPath+'防跌倒.jpg';
      GridppReport11.ControlByName(sVCLName).AsPictureBox.Picture.LoadFromFile(sFileName);
    end;

    2、明细列表中打印指定目录中的图像:

    (1)指定列字段的打印行为“自由格”,在该字段列中。加入PictureBox控件,设置参数:充满等等。

    (2)在GridppReport1FetchRecord事件中。代码:

GridppReport1.DetailGrid.Recordset.Append();
    if (sFileName<>'') and FileExists(sFileName) then
      GridppReport1.ControlByName('Picturebox').AsPictureBox.LoadFromFile(sFileName);
    Gr[1].Value := A[i,1];
    Gr[2].Value := A[i,2];
    Gr[3].Value := A[i,3];
    if (sFileName1<>'') and FileExists(sFileName1) then
      GridppReport1.ControlByName('Picturebox1').AsPictureBox.LoadFromFile(sFileName1);
    Gr[5].Value := A[i,5];
    Gr[6].Value := A[i,6];
    Gr[7].Value := A[i,7];
    GridppReport1.DetailGrid.Recordset.Post();

锐浪怎么通过java设置明细表格内容的大小_.net

     3、明细列表中打印数据库读取的图像:

    (1)从字段中读出图像数据到内存中,然后图像框从内存中载入数据

procedure TForm1.GridppReport1Initialize(Sender: TObject);
var
    pMemoryStream: TMemoryStream;
    Buffer: PChar;
    MemSize: Integer;
begin
    qryCategory.Open();
    pMemoryStream := TMemoryStream.Create();
    qryCategoryPicture.SaveToStream( pMemoryStream );
    pMemoryStream.Position := 0;
    MemSize := pMemoryStream.Size;
    Buffer := AllocMem(MemSize);
    try
      pMemoryStream.Read(Buffer^, MemSize);
      GridppReport1.ControlByName('MemoryPictureBox').
          AsPictureBox.LoadFromMemory(Byte(Buffer[0]), MemSize);
    finally
      FreeMem(Buffer, MemSize);
    end;
    pMemoryStream.Free;
    qryCategory.Close();
end;

    (2)由二进制字段直接读取

private
    FFilePictureBox: IGRPictureBox;
    FPictureFileField: IGRField;

procedure TForm1.GridppReport1Initialize(Sender: TObject);
begin
    FFilePictureBox := GridppReport1.ControlByName('FilePictureBox').AsPictureBox;
    FPictureFileField := GridppReport1.FieldByName('PictureFile');
end;