View Single Post
Old 01-30-2020, 03:14 PM   #937
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Quote:
Originally Posted by Edgemeal View Post
Excellent question! I messed around with that a little bit before, PNG's look OK but I was never really sure I'm doing it correctly , would love to get Julian's feedback!

Capture screen area to PNG,..
Code:
function CaptureScreenArea(x,y,w,h,filename)
  sourceHDC = reaper.JS_GDI_GetScreenDC()
  destBmp = reaper.JS_LICE_CreateBitmap(true,w,h)
  destDC = reaper.JS_LICE_GetDC(destBmp)
  reaper.JS_GDI_Blit(destDC, 0, 0, sourceHDC, x, y, w, h)
  reaper.JS_LICE_WritePNG(filename, destBmp, false)
  reaper.JS_LICE_DestroyBitmap(destBmp)
end

Capture a window to PNG,..
Code:
function GetBounds(hwnd)
  local _, left, top, right, bottom = reaper.JS_Window_GetRect(hwnd)
  return left, top, right-left, bottom-top
end

function CaptureWindow(windowTitle, filename, win10) 
  window = reaper.JS_Window_FindTop(windowTitle, true)
  if not window then reaper.MB('Window not found!','Capture Error',0) return end
  sourceHDC = reaper.JS_GDI_GetWindowDC(window)
  _,_,w,h = GetBounds(window)
  srcx,srcy = 0,0
  if win10 then srcx=7 w=w-14 h=h-7 end -- workaround for invisible Win10 borders.
  dest_bmp = reaper.JS_LICE_CreateBitmap(true,w,h)
  destDC = reaper.JS_LICE_GetDC(dest_bmp)
  -- copy source to dest & write PNG
  reaper.JS_GDI_Blit(destDC, 0, 0, sourceHDC, srcx, srcy, w, h)
  reaper.JS_LICE_WritePNG(filename, dest_bmp, false) 
  -- clean up resources
  reaper.JS_GDI_ReleaseDC(window, sourceHDC)
  reaper.JS_LICE_DestroyBitmap(dest_bmp)
end
Thank You, Savior of the Universe
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote