Код:
function ScreenShot(hwnd: THandle): TStream;
var
rc: TRect;
hDC1, hSrcDC: HDC;
hBmp: HBITMAP;
tBmp: TBitmap;
r: Trect;
color: TColor;
color_str: string;
list: TStringList;
x, y: integer;
stream:TStream;
begin
tBmp := TBitmap.Create;
GetWindowRect(hwnd, r);
hDC1 := GetDc(hwnd);
hSrcDC := CreateCompatibleDC(hDC1);
hBmp := CreateCompatibleBitmap(hDC1, r.Right - r.Left, r.Bottom - r.Top);
SelectObject(hSrcDC, hBmp);
PrintWindow(hwnd, hSrcDC, 0);
BitBlt(hDC1, 0, 0, r.Right - r.Left, r.Bottom - r.Top, hSrcDC, 0, 0, SRCCOPY);
tBmp.Handle := hBmp;
DeleteObject(hBmp);
DeleteDC(hSrcDC);
ReleaseDC(hwnd, hDC1);
color := tBmp.Canvas.Pixels[100, 100]; // -1
color_str := IntTostr(GetRValue(color)) + IntTostr(GetGValue(color)) + IntTostr(GetBValue(color));
ShowMessage('2 ' + color_str); // Выкидывает цвет "255255255", хотя там не он.
tBmp.SaveToStream(stream); // Вылетает, говорит "Bitmap image is not valid"
Result := stream;
end;
Добавлено через 11 минут
Не знаю как так получается, но уже в который раз обратившись сюда за помощью, сразу нахожу решение самостоятельно)