Page 1 of 1

snapshot of the browser

Posted: Mon May 02, 2022 10:25 pm
by pushca
Hello. I'm trying to get a snapshot of the browser, I'm using CopyRect but I get a white screen. Help me solve this problem

Re: snapshot of the browser

Posted: Tue May 03, 2022 1:46 pm
by solaris
This worked for me. Taken from one of the sample projects:

Code: Select all

// init stream...
procedure TForm1.FormCreate(Sender: TObject);
begin
   FSnapshotFileStream := nil;   
end;

// free stream (if still active)
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
   FreeAndNil(FSnapshotFileStream);
end;

// take snapshot...
procedure TForm1.Snapshot(filename:string);
var
   adapter:IStream;
begin
   FreeAndNil(FSnapshotFileStream);
   SnapshotFileStream := TFileStream.Create(filename, fmCreate);
   try
      adapter := TStreamAdapter.Create(FSnapshotFileStream, soReference);
      browser.CapturePreview(COREWEBVIEW2_CAPTURE_PREVIEW_IMAGE_FORMAT_JPEG, adapter);
   finally
      adapter := nil;
   end;
end;

// snapshot finished...
procedure TForm1.OnCapturePreviewCompleted(Sender: TObject;aErrorCode: HRESULT);
begin
   FreeAndNil(FSnapshotFileStream);
end;

Re: snapshot of the browser

Posted: Wed May 04, 2022 7:21 am
by pushca
Thanks! It works! The best