TfrxPictureView don't accept different PNG's anymore

edited November 2015 in FastReport VCL 5
Hi,

In FastReport v4 I used to fill TfrxPictureView with a TClientDataset-field from a database which contains a PNG-picture. In FastReport v5.3 and v5.3.14 this don't work anymore.

In frxReport.OnManualBuild :
Pict := MyReport.FindObject('Picture1') as TfrxPictureView;
if (Pict <> nil) then
begin
  MS := TMemoryStream.Create;
  try
    cdsLookupConfigLOGO_RAPPORT.SaveToStream(MS);

    Pict.LoadPictureFromStream(MS);
  finally
    MS.Free;
  end;
end;

OR in frxReport.OnBeforePrint :
if Sender.Name = 'Picture1' then
begin
  MS := TMemoryStream.Create;
  try
    cdsLookupConfigLOGO_RAPPORT.SaveToStream(MS);

    TfrxPictureView(Sender).LoadPictureFromStream(MS);
  finally
    MS.Free;
  end;
end;

You can add a PNG in the TfxrPictureView.Picture property, but if you want to use different PNG-pictures for each report that's no option, so this has te be done the way I did it before or to define a frxDBDataSet to the property TfrxPictureView.DataSet and the field to TfrxPictureView.DataField.

All possibilities mentioned above work fine in v4 but in not v5 with PNG's, just (a.f.a.i.k.) JPG's.

How can I solve this problem ?

[Edit]

I think it has something to do with recognising with the defined const in frxClass.pas of OriginalPNGHeader
const
  OriginalPngHeader: array[0..7] of AnsiChar = (#137, #80, #78, #71, #13, #10, #26, #10);

When compiling I get a warning: "frxClass(7517: W1061 Narrowing given WideChar constant (#$0089) to AnsiChar lost information" so I guess the header of the PNG-picture isn't recognized as a PNG because of #137 ....
[/Edit]

Comments

  • The problem is solved with changing the const OriginalPngHeader (deleted #137 and made the array 1 smaller)
    const
    //OriginalPngHeader: array[0..7] of AnsiChar = (#137, #80, #78, #71, #13, #10, #26, #10);
      OriginalPngHeader: array[0..6] of AnsiChar =       (#80, #78, #71, #13, #10, #26, #10);
    

    I left the var PNGHeader its original size.
      PNGHeader: array[0..7] of AnsiChar;
    

    And in TfrxPictureView.LoadPictureFromStream
        {$IFDEF PNG}
        if not bOK then
        begin
          if (s.Size-pos) >= SizeOf(PNGHeader) then
          begin
            // try png header
            s.ReadBuffer(PNGHeader, SizeOf(PNGHeader));
            s.Position := pos;
    //      if PNGHeader = OriginalPngHeader then
            // replaced compare above with compare down here
            if (PNGHeader[0] = AnsiChar($0089)) and (copy(PNGHeader, 2, 8) = OriginalPngHeader) then
            begin
              NewGraphic := TPngObject.Create;
              bOK := True;
            end;
          end;
        end;
        {$ENDIF}
    

    Somebody knows a better solution ?

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.