title: AutoHotkey-GDIp: Capture a screenshot from a hardware accelerated window
body: <p>I am currently working on a small script which captures a screenshot from a hardware accelerated window in BlueStacks.</p>
  
  <p>Problem is, that it appears the window must be hardware accelerated, so the screen capture is saving a black square.</p>
  
  <p>I am using AutoHotkey for my scripting, and have added the GDIp libraries for access to GDI+.  </p>
  
  <p>I suspect the problem is that GDIp cannot grab the data using PrintWindow due to the software pushing the frame directly to the GPU, but there must be a way to capture this frame.  </p>
  
  <p>My script:</p>
  
  <pre><code>#SingleInstance, Force
  #NoEnv
  SetBatchLines, -1
  OnExit, Exit
  
  #Include Gdip.ahk
  #Include GDIpHelper.ahk
  
  SetUpGDIP()
  
  WinGet, hwnd, ID, BlueStacks App Player
  
  pBitmap := Gdip_BitmapFromHWND(hwnd)
  
  Gdip_SaveBitmapToFile(pBitmap, "TestOutput.png", 100)
  
  Gdip_DisposeImage(pBitmap)
  
  return
  </code></pre>
  
  <p>The actual screen to capture:</p>
  
  <p><img src="https://i.stack.imgur.com/ZjoBN.jpg" alt="Manual Screenshot done with Alt+PrtScrn"></p>
  
  <p>The actual file output by my script:
  <img src="https://i.stack.imgur.com/7SbUN.png" alt="Black square, proper dimensions so it&#39;s seeing the right thing, but can&#39;t get the pixel data"></p>
  
  <p>Any ideas on where to go or any kind of instruction on how to access the framebuffer perhaps?  It can't be something no one has needed to do before.</p>