snapshot of the browser

Post Reply
pushca
Posts: 37
Joined: Sat Dec 04, 2021 5:09 pm

snapshot of the browser

Post 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
solaris
Posts: 3
Joined: Wed Apr 27, 2022 1:01 pm

Re: snapshot of the browser

Post 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;
pushca
Posts: 37
Joined: Sat Dec 04, 2021 5:09 pm

Re: snapshot of the browser

Post by pushca »

Thanks! It works! The best
Post Reply