如何在全屏opengl游戏Delphi中截图?

如何在全屏opengl游戏Delphi中截图?,delphi,opengl,screenshot,Delphi,Opengl,Screenshot,可能重复: 我需要帮助。我需要截图全屏opengl游戏delphi源代码。这里有一些我编造的东西,你还没有指定delphi版本,所以这是在D2010中编写的,不幸的是我唯一的游戏是counter strike 1.6,结果是一个黑色图像,但我很确定你可以从这里开始工作(这是一项匆忙的工作,但我没有太多时间),所以下面是代码: function TakeGameShot(const AFileName: string; const AWidth, AHeight: Integer): Boole

可能重复:


我需要帮助。我需要截图全屏opengl游戏delphi源代码。

这里有一些我编造的东西,你还没有指定delphi版本,所以这是在D2010中编写的,不幸的是我唯一的游戏是counter strike 1.6,结果是一个黑色图像,但我很确定你可以从这里开始工作(这是一项匆忙的工作,但我没有太多时间),所以下面是代码:

function TakeGameShot(const AFileName: string; const AWidth, AHeight: Integer): Boolean;
var
  LPixels: array of Byte;
  LLine: PByteArray;
  LBitmap: TBitmap;
  Index: Integer;
begin
  Result := False;
  LBitmap := TBitmap.Create;
  try
    LBitmap.PixelFormat := pf24bit;
    LBitmap.Height := AHeight;
    LBitmap.Width := AWidth;

    //  width * height * 3 bytes/pixel
    SetLength(LPixels, AWidth * AHeight * 3);

    //  tell open gl which buffer we're interested in
    glReadBuffer(GL_BACK);
    //  read pixels
    glReadPixels(0, 0, AWidth, AHeight, GL_RGB, GL_UNSIGNED_BYTE, @LPixels);
    //  scan each line from bitmap
    for Index := 0 to AHeight -1 do begin
      LLine := LBitmap.ScanLine[ Index ];
      //  move data from LPixels to LLine, data size = Width * 3(bytes/pixel)
      Move(LPixels[ Index * AWidth ], LLine^[0], AWidth * 3);
    end; // for Index := 0 to AHeight -1 do begin
    //  save the bitmap
    LBitmap.SaveToFile(AFileName);
    //  if we reached this line, we're pretty much OK
    Result := True;
  finally
    LBitmap.Free;
  end;
end;

你检查过我贴在你上一个问题上的链接了吗?