TPngImage.LoadFromStream

I try to load an image (png) into a TfrxPictureView in the OnBeforePrint event. The png exists in a TMemoryStream (ms in the following code snippets).
This code works fine:
png := TPngImage.Create;
fn := 'c:\temp\1.png';
ms.SaveToFile(fn);
png.LoadFromFile(fn);
Picture1.Picture.Assign(png);
png.Free;

But I don't want to save the MemoryStream to file:
png := TPngImage.Create;
png.LoadFromStream(ms); // this function is not available
Picture1.Picture.Assign(png);
png.Free;

Is there a way to load the data from the MemoryStream into TfrxPictureView without saving it to file?

greetings
Gerhard

Comments

  • edited 5:45AM
    it can be done in the delphi user function:
    function GetImageFromURL(url: string; Adress: integer): string;
    var ms: TMemoryStream;
        response: integer;
        http: TIdHTTP;
        image: TfrxPictureView;
    begin
      http := TIdHTTP.Create(nil);
      ms := TMemoryStream.Create;
      try
        http.Get(url, ms);
        response := http.ResponseCode;
        if response <> 200 then begin
          // ToDo: no modal dialog
          ShowMessage('Error');
          exit;
        end;
        image := TfrxPictureView(pointer(Adress));
        image.LoadPictureFromStream(ms);
      except
        on E: Exception do begin
          // ToDo: no modal dialog
          ShowMessage('Error: ' + E.Message);
        end;
      end;
      ms.free;
      http.Free;
    end;
    

    Script code:
    procedure Picture1OnBeforePrint(Sender: TfrxComponent);
    var url: string;                                  
        p: pointer;                             
    begin
      url := 'http://ojw.dev.openstreetmap.org/StaticMap/?'+
             'lat='+<LeiAtom."lat">+
             '&lon='+<LeiAtom."long">+
             '&z=14'+
             '&layer=cloudmade_2'+
             '&mode=Export'+
             '&show=1';
      p := Sender;                                            
      GetImageFromURL(url, p);
    end;
    
  • gpigpi
    edited 5:45AM
    Try to use TfrxReport.OnBeforePrint event
        if Sender.Name = 'Picture1' then
        TfrxPictureView(Sender).LoadPictureFromStream(ms);
    

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.