You've already forked CEF4Delphi
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:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user