View Single Post
Old 02-04-2020, 02:36 PM   #945
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 2,130
Default

I experimented with the problem further and it seems, that at least on Windows 7, the capturing of the gfx.init-window is not entirely possible.
Run the code and move windows on top of the gfx.init-window. You'll see the problems in the written pngs very quickly, as you can see the windows on top of the gfx.init-window in the written pngs.

I've looked into Julian's code and it seems, that this isn't a problem in his code, so I suspect, there's a WDL-bug somewhere.

Code:
-- This script will attempt to save a screenshot of the gfx-window once a second.
-- Just move some windows in front of the gfx-window to see the effect.
-- It captures the right window, BUT: also what's before it.
-- Maybe this is a Reaper-bug?

-- Set this output path and run the program.
-- In this path, all screenshots will be stored.
output_path="c:\\temp\\A2/"



-- the function for capturing, which is mostly your code, slightly altered(and simplified for this demo)
-- still, the bug remains

ultraschall={}
function ultraschall.CaptureWindowAsPNG(windowTitle, filename_with_path, x, y, w, h, win10)
  local window
  
  window = reaper.JS_Window_FindTop(windowTitle, true)
  
  local sourceHDC = reaper.JS_GDI_GetWindowDC(window)
  
  local _, Aleft, Atop, Aright, Abottom = reaper.JS_Window_GetRect(window)
  Aright=Aright-Aleft
  Abottom=Abottom-Atop
  if x==nil then x=0 end
  if y==nil then y=0 end
  if w==nil then w=Aright end
  if h==nil then h=Abottom end
  
  if win10 then srcx=7 w=w-14 h=h-7 end -- workaround for invisible Win10 borders.
  local dest_bmp = reaper.JS_LICE_CreateBitmap(true,w,h)
  local destDC = reaper.JS_LICE_GetDC(dest_bmp)
  -- copy source to dest & write PNG
  reaper.JS_GDI_Blit(destDC, 0, 0, sourceHDC, x, y, w, h)
  local writeable = reaper.JS_LICE_WritePNG(filename_with_path, dest_bmp, false)
  -- clean up resources
  reaper.JS_GDI_ReleaseDC(window, sourceHDC)
  reaper.JS_LICE_DestroyBitmap(dest_bmp)
  if writeable==false then return 8 end
  return writeable
end




-- window
gfx.init("Tudelu bugtest")

-- prepare some variables and stuff
B=gfx.loadimg(1, reaper.GetResourcePath().."/data/track_icons/group.png")
gfx.x=-50
gfx.y=-300
gfx.blit(1,14,0)
gfx.setfont(1, "Arial", 50, 0)
counter=0
index=0


-- the main-defer-loop, which stores a screenshot of the gfx-window every second
function main()
  counter=counter+1
  if counter==30 then
    index=index+1
    if index<10 then zero="0" else zero="" end
    A=ultraschall.CaptureWindowAsPNG("Tudelu bugtest", output_path..zero..index..".png", 0, 0, gfx.w, gfx.h, true)
    counter=0
  end
  reaper.defer(main)
end

main()
__________________
Use she/her, when contacting me, please. Thanks :) Not mentoring via PMs, sorry.
Ultraschall-API - 1200 ReaScript functions for Reaper - Reaper Internals - Developerdocs4Reaper - Donate, if you want
mespotine is offline   Reply With Quote