Forum > General
Screenshot shows Black screen!
(1/1)
Vladmir:
Why is this saving a black screen? I am trying to do a screencapture with mouse cursor. I tried it and it saves a black screen other than a normal screen ,it is supposed to save the screen and cursor.
My code looks thus
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit ScreenCapClassEx; {$mode objfpc}{$H+} interface uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, windows; type { TForm1 } TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private public end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure DrawCursor (ACanvas:TCanvas; Position:TPoint) ;var HCursor : THandle;begin HCursor := GetCursor; DrawIconEx(ACanvas.Handle, Position.X, Position.Y, HCursor, 32, 32, 0, 0, DI_NORMAL) ;end; function CaptureWindow(const WindowHandle: HWnd): Graphics.TBitmap;var DC: HDC; wRect: TRect; CurPos: TPoint;begin DC := GetWindowDC(WindowHandle); Result := Graphics.TBitmap.Create; try GetWindowRect(WindowHandle, wRect); Result.Width := wRect.Right - wRect.Left; Result.Height := wRect.Bottom - wRect.Top; BitBlt(Result.Canvas.Handle, 0, 0, Result.Width, Result.Height, DC, 0, 0, SRCCOPY); GetCursorPos(CurPos); DrawCursor(Result.Canvas, CurPos); finally ReleaseDC(WindowHandle, DC); end;end; procedure TForm1.Button1Click(Sender: TObject);var Bmp: Graphics.TBitmap;begin Bmp := CaptureWindow(GetDesktopWindow); Bmp.SaveToFile('C:\Users\****\Desktop\test\FullScreenCap.bmp'); Bmp.Free; showmessage('Screen captured.'); ReadLn;end; end.
balazsszekely:
1.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- //... DC := GetWindowDC(WindowHandle); Result := Graphics.TBitmap.Create; Result.PixelFormat := pf32bit; <--insert this line //...
2.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- //... Bmp := CaptureWindow(GetDesktopWindow); Bmp.Canvas.Changed; <--insert this line //...
Vladmir:
Thank you! O:-)
Navigation
[0] Message Index