1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-11-23 21:34:53 +02:00

Added TFMXChromium.TakeSnapshot

- Added TFMXChromium.SaveAsBitmapStream
- Added TChromium.SaveAsBitmapStream
- Fixed bug #253
This commit is contained in:
Salvador Díaz Fau
2020-01-02 20:02:47 +01:00
parent fd1e936198
commit e53cc7ee5d
7 changed files with 321 additions and 47 deletions

View File

@@ -83,6 +83,7 @@ type
procedure SetFormTopTo(const y : Integer);
function CreateBrowser(const aBrowserParent : TWinControl = nil; const aWindowName : ustring = ''; const aContext : ICefRequestContext = nil; const aExtraInfo : ICefDictionaryValue = nil) : boolean; overload; virtual;
function SaveAsBitmapStream(var aStream : TStream) : boolean;
function TakeSnapshot(var aBitmap : TBitmap) : boolean;
end;
@@ -289,10 +290,34 @@ begin
Result := inherited CreateBrowser(TempHandle, TempRect, aWindowName, aContext, aExtraInfo);
end;
function TChromium.SaveAsBitmapStream(var aStream : TStream) : boolean;
{$IFDEF MSWINDOWS}
var
TempDC : HDC;
TempRect : TRect;
{$ENDIF}
begin
Result := False;
{$IFDEF MSWINDOWS}
if not(FIsOSR) and (FRenderCompHWND <> 0) and (aStream <> nil) then
begin
TempDC := GetDC(FRenderCompHWND);
if (TempDC <> 0) then
try
GetClientRect(FRenderCompHWND, TempRect);
Result := CopyDCToBitmapStream(TempDC, TempRect, aStream);
finally
ReleaseDC(FRenderCompHWND, TempDC);
end;
end;
{$ENDIF}
end;
function TChromium.TakeSnapshot(var aBitmap : TBitmap) : boolean;
{$IFDEF MSWINDOWS}
var
TempHWND : HWND;
TempDC : HDC;
TempRect : TRect;
TempWidth : Integer;
@@ -302,30 +327,29 @@ begin
Result := False;
{$IFDEF MSWINDOWS}
if not(FIsOSR) then
if not(FIsOSR) and (FRenderCompHWND <> 0) then
begin
TempHWND := GetWindowHandle;
GetClientRect(FRenderCompHWND, TempRect);
if (TempHWND <> 0) then
begin
GetClientRect(TempHWND, TempRect);
TempWidth := TempRect.Right - TempRect.Left;
TempHeight := TempRect.Bottom - TempRect.Top;
TempWidth := TempRect.Right - TempRect.Left;
TempHeight := TempRect.Bottom - TempRect.Top;
if (TempWidth <= 0) or (TempHeight <= 0) then exit;
if (aBitmap <> nil) then FreeAndNil(aBitmap);
if (aBitmap <> nil) then FreeAndNil(aBitmap);
aBitmap := TBitmap.Create;
aBitmap.Height := TempHeight;
aBitmap.Width := TempWidth;
aBitmap := TBitmap.Create;
aBitmap.Height := TempHeight;
aBitmap.Width := TempWidth;
TempDC := GetDC(TempHWND);
try
Result := BitBlt(aBitmap.Canvas.Handle, 0, 0, TempWidth, TempHeight,
TempDC, 0, 0, SRCCOPY);
finally
ReleaseDC(TempHWND, TempDC);
end;
TempDC := GetDC(FRenderCompHWND);
if (TempDC <> 0) then
try
Result := BitBlt(aBitmap.Canvas.Handle, 0, 0, TempWidth, TempHeight,
TempDC, 0, 0, SRCCOPY);
finally
ReleaseDC(FRenderCompHWND, TempDC);
end;
end;
{$ENDIF}