Hola a Todos, <br><br><br>Necesito capturar la pantalla en Windows, solo que los intentos que he realizado, ninguno captura las interface transparentes como por ejemplo la ventana de buscar y reemplazar del notepad++.<br><br>
He intentado estos metodos y todos funcionan para capturar pantalla pero ninguno recoge las transparencias. ( no se ven las ventanas transparentes, como si no existiesen)<br><span style="color: rgb(25, 25, 25); font-family: Helvetica,Arial,sans-serif; font-size: 15px; line-height: 26px;"><br>
</span><span style="color: rgb(25, 25, 25); font-family: Helvetica,Arial,sans-serif; font-size: 15px; line-height: 26px;"><pre style="padding: 1em; border: 1px dashed gray; color: black; background-color: rgb(249, 249, 249); overflow: auto;">
from PIL import ImageGrab
import time
time.sleep(5)
box = (100,100,400,400)
ImageGrab.grab().crop(box).save("screen_capture.jpg", "JPEG")</pre></span><br><div><span style="color: rgb(25, 25, 25); font-family: Helvetica,Arial,sans-serif; font-size: 15px; line-height: 26px;"><pre style="padding: 1em; border: 1px dashed gray; color: black; background-color: rgb(249, 249, 249); overflow: auto;">
<span style="font-family: Arial; font-size: medium;"><pre><code><font color="#3f7f5f"></font><font color="#7f0055"><b>import</b></font> Image <font color="#3f7f5f"></font><br><font color="#7f0055"><b>try</b></font>:
<font color="#3f7f5f"># built-in driver (1.1.3 and later)
</font> grabber = Image.core.grabscreen
<font color="#7f0055"><b>except</b></font> AttributeError:
<font color="#3f7f5f"># stand-alone driver (pil plus)
</font> <font color="#7f0055"><b>import</b></font> _grabscreen
grabber = _grabscreen.grab
<font color="#3f7f5f">##
</font><font color="#3f7f5f"># (New in 1.1.3) Take a snapshot of the screen. The pixels inside the
</font><font color="#3f7f5f"># bounding box are returned as an "RGB" image. If the bounding box is
</font><font color="#3f7f5f"># omitted, the entire screen is copied.
</font><font color="#3f7f5f">#
</font><font color="#3f7f5f"># @param bbox What region to copy. Default is the entire screen.
</font><font color="#3f7f5f"># @return An image
</font><font color="#3f7f5f"># @since 1.1.3
</font>
<font color="#7f0055"><b>def</b></font> grab(bbox=None):
size, data = grabber()
im = Image.fromstring(
<font color="#2a00ff">"RGB"</font>, size, data,
<font color="#3f7f5f"># RGB, 32-bit line padding, origo in lower left corner
</font> <font color="#2a00ff">"raw"</font>, <font color="#2a00ff">"BGR"</font>, (size[0]*3 + 3) & -4, -1
)
<font color="#7f0055"><b>if</b></font> bbox:
im = im.crop(bbox)
<font color="#7f0055"><b>return</b></font> im
<font color="#3f7f5f">##
</font><font color="#3f7f5f"># (New in 1.1.4) Take a snapshot of the clipboard image, if any.
</font><font color="#3f7f5f">#
</font><font color="#3f7f5f"># @return An image, a list of filenames, or None if the clipboard does
</font><font color="#3f7f5f"># not contain image data or filenames. Note that if a list is
</font><font color="#3f7f5f"># returned, the filenames may not represent image files.
</font><font color="#3f7f5f"># @since 1.1.4
</font>
<font color="#7f0055"><b>def</b></font> grabclipboard():
debug = 0 <font color="#3f7f5f"># temporary interface
</font> data = Image.core.grabclipboard(debug)
<font color="#7f0055"><b>if</b></font> Image.isStringType(data):
<font color="#7f0055"><b>import</b></font> BmpImagePlugin, StringIO
<font color="#7f0055"><b>return</b></font> BmpImagePlugin.DibImageFile(StringIO.StringIO(data))
<font color="#7f0055"><b>return</b></font> data</code></pre></span></pre></span></div><div><span style="color: rgb(25, 25, 25); font-family: Helvetica,Arial,sans-serif; font-size: 15px; line-height: 26px;"><pre style="padding: 1em; border: 1px dashed gray; color: black; background-color: rgb(249, 249, 249); overflow: auto;">
<span style="font-family: Arial; font-size: medium;"><pre><span style="font-family: Arial; font-size: medium;"><pre><span style="font-family: Arial; font-size: medium;"><pre><code><span style="font-family: 'Courier New',Courier,monospace; white-space: nowrap; font-size: 10px; line-height: 22px;"><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
import win32gui, win32ui, win32con, win32api</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
hwnd = win32gui.GetDesktopWindow()</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
print hwnd</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
# you can use this to capture only a specific window</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
#l, t, r, b = win32gui.GetWindowRect(hwnd)</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
#w = r - l</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
#h = b - t</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
# get complete virtual screen including all monitors</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
SM_XVIRTUALSCREEN = 76</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
SM_YVIRTUALSCREEN = 77</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
SM_CXVIRTUALSCREEN = 78</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
SM_CYVIRTUALSCREEN = 79</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
w = vscreenwidth = win32api.GetSystemMetrics(SM_CXVIRTUALSCREEN)</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
h = vscreenheigth = win32api.GetSystemMetrics(SM_CYVIRTUALSCREEN)</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
l = vscreenx = win32api.GetSystemMetrics(SM_XVIRTUALSCREEN)</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
t = vscreeny = win32api.GetSystemMetrics(SM_YVIRTUALSCREEN)</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
r = l + w</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
b = t + h</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
print l, t, r, b, ' -> ', w, h</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
hwndDC = win32gui.GetWindowDC(hwnd)</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
mfcDC = win32ui.CreateDCFromHandle(hwndDC)</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
saveDC = mfcDC.CreateCompatibleDC()</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
saveBitMap = win32ui.CreateBitmap()</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
saveBitMap.CreateCompatibleBitmap(mfcDC, w, h)</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
saveDC.SelectObject(saveBitMap)</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
saveDC.BitBlt((0, 0), (w, h), mfcDC, (l, t), win32con.SRCCOPY)</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
saveBitMap.SaveBitmapFile(saveDC, 'screencapture.bmp')</li></span></code></pre></span></pre></span></pre></span></pre></span></div><span style="font-family: Arial; font-size: medium;"><pre><code><font color="#3f7f5f"><br>
</font></code></pre><pre><span style="font-family: Arial; font-size: medium;"><pre><code></code></pre></span></pre></span><br><div><br></div><div><br></div><span style="font-family: 'Courier New',Courier,monospace; white-space: nowrap;"><ol start="1" style="background-color: rgb(231, 229, 220); margin-top: 0px; margin-bottom: 0px; font-size: 10px; line-height: 22px;">
<li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
import wx</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
app = wx.PySimpleApp()</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
context = wx.ScreenDC()</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
r, b = context.GetSize()</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
# i have a second monitor left of my primary, so these value are negativ</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
l, t = (-1280, -256) # coulfn't find a wx function to get these</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
w, h = (r - l, b - t)</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
bitmap = wx.EmptyBitmap(w, h, -1)</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
memory = wx.MemoryDC()</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
memory.SelectObject(bitmap)</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
memory.Blit(0, 0, w, h, context, l, t)</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
memory.SelectObject(wx.NullBitmap)</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
#bitmap.SaveFile("screencapture.bmp", wx.BITMAP_TYPE_BMP)</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
#bitmap.SaveFile("screencapture.jpg", wx.BITMAP_TYPE_JPEG)</li><li style="font-size: 12px; background-color: white; font-family: 'Courier New',Courier,monospace; border-bottom: 1px solid rgb(240, 240, 240); border-left: 3px solid green; font-weight: normal; line-height: 18px; text-indent: 5px; padding: 2px 0px;">
bitmap.SaveFile("screencapture.png", wx.BITMAP_TYPE_PNG)</li></ol></span><br clear="all"><br>-- <br><font color="#000099"><b>Josu Rodriguez Vilda</b></font><div><font color="#000099"><b><br></b></font></div><div>
<font color="#000099"><b><br></b></font><br></div><br>