rj
2014-01-18 16:53:31
I was bored and messing around with simba last night, and I wrote up a little take screenshot function..
[spoiler=full]
It's pretty darn slow, (4000 ms for my like 1900X1700 screen or something) I didn't really do it for speed or any purpose, I just wanted to make the function on my own without the help of anything (sort of)
But I was wondering, how could I replicate this in c++? How would I actually capture the window and then display the image?
my c++ code so far:
lol
procedure takeScreenshot(x1, y1, x2, y2:integer);
var
i, k, c:integer;
begin
setLength(tpa, (x2 - x1) * (y2 - y1));
setLength(colors, length(tpa));
for i := x1 to x2 - 1 do
for k := y1 to y2 - 1 do
begin
tpa[c] := point(i, k);
Colors[c] := getColor(i, k);
c := c + 1;
end;
end; [spoiler=full]
var
tpa:tpointarray;
colors:tintegerarray;
procedure showScreenShot(x1, y1, x2, y2:integer);
var
tpa2:tpointarray;
bmp, i:integer;
begin
setLength(tpa2, length(tpa));
for i := 0 to high(tpa) do
tpa2[i] := point(tpa[i].x - x1, tpa[i].y - y1);
bmp := createBitmap(x2 - x1, y2 - y1);
fastsetpixels(bmp, tpa2, colors);
DisplayDebugImgWindow(x2 - x1 + 1, y2 - y1 + 1);
DrawBitmapDebugImg(Bmp);
freebitmap(bmp);
end;
procedure takeScreenshot(x1, y1, x2, y2:integer);
var
i, k, c:integer;
begin
setLength(tpa, (x2 - x1) * (y2 - y1));
setLength(colors, length(tpa));
for i := x1 to x2 - 1 do
for k := y1 to y2 - 1 do
begin
tpa[c] := point(i, k);
Colors[c] := getColor(i, k);
c := c + 1;
end;
showScreenShot(x1, y1, x2, y2);
end;
var
t:integer;
begin
t := getsystemTime;
takeScreenshot(2, 2, 843, 857);
writeln('Took ' , GetsystemTime - t, ' ms');
end.[/spoiler]It's pretty darn slow, (4000 ms for my like 1900X1700 screen or something) I didn't really do it for speed or any purpose, I just wanted to make the function on my own without the help of anything (sort of)
But I was wondering, how could I replicate this in c++? How would I actually capture the window and then display the image?
my c++ code so far:
#include <iostream>
#include<windows.h>
using namespace std;
void takeScreenshot(int x1, int y1, int x2, int y2)
{
std::cout << "Hello World!";
}
int main()
{
takeScreenshot(0, 0, 5, 5)
return 0;
}lol