Fables Alive
Fables Alive

Reputation: 2810

howto get Screenshot of tchromium loaded document programmatically?

I couldnt find a proper way to get picture of the loaded document in tchromium vcl control in a form.

looking for a method to get document as a bitmap of file or stream. delphi / tchromium component

Upvotes: 2

Views: 1894

Answers (5)

Fabricius Lopes
Fabricius Lopes

Reputation: 11

Sorry for post on almost dead question, but for future devs its important know that chromium ( CEF4 ) have a method "Chromium.TakeSnapshot(bmp)" that get a screenshot of loaded component.

Upvotes: 1

laggyluk
laggyluk

Reputation: 195

The off screen renderer component has OnPaint method that is used to copy data to screen and you could use it for saving image

Upvotes: 0

delphirules
delphirules

Reputation: 7438

I think it will be easier to take a snapshot from the entire application screen. Try this :

function screenshot: boolean;
var
  Bild : TBitmap;
  jpg : tjpegimage;
  c: TCanvas;
   r: TRect;
begin
try
   c := TCanvas.Create;
   bild := tbitmap.Create;
   c.Handle := GetWindowDC(GetDesktopWindow);
   try
    r := Rect(0, 0, Screen.Width, Screen.Height);
     Bild.Width := Screen.Width;
     Bild.Height := Screen.Height;
     Bild.Canvas.CopyRect(r, c, r);
     JPG := TJpegImage.Create;
     jpg.smoothing := true;
     jpg.CompressionQuality := 60 ;
     jpg.Assign(bild);
     jpg.compress;
     jpg.SaveToFile(dircamp+'\screen.jpg');
   finally
    ReleaseDC(0, c.Handle);
     Bild.free;
     jpg.free;
     c.Free;
   end;
except
end;

Upvotes: 0

Fables Alive
Fables Alive

Reputation: 2810

Save to picture function is no longer avaible in DCEF3.but cef-r2.31 has it.

procedure Tfmmain.Button1Click(Sender: TObject);
var
  lol:TPicture;
begin
  lol:=TPicture.Create;
  Chromium1.Browser.GetBitmap(PET_VIEW,lol.Bitmap);
  lol.SaveToFile('c:\lol.bmp');
  lol.Free;
  lol:=nil;
end;

Upvotes: 0

Carlos Cortez
Carlos Cortez

Reputation: 170

TChromium inherits TWinControl, thus it has a HANDLE that can be used with BitBlt to take a "Screenshot" of the specified component. This article pretty much covers it all.

Upvotes: 1

Related Questions