<br><br><div class="gmail_quote">2010/10/7 Josu Rodriguez Vilda <span dir="ltr">&lt;<a href="mailto:jrvilda@gmail.com">jrvilda@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
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(&quot;screen_capture.jpg&quot;, &quot;JPEG&quot;)</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="#7f0055"><b>import</b></font> Image <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 &quot;RGB&quot; 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">&quot;RGB&quot;</font>, size, data,
        <font color="#3f7f5f"># RGB, 32-bit line padding, origo in lower left corner
</font>        <font color="#2a00ff">&quot;raw&quot;</font>, <font color="#2a00ff">&quot;BGR&quot;</font>, (size[0]*3 + 3) &amp; -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: &#39;Courier New&#39;,Courier,monospace; white-space: nowrap; font-size: 10px; line-height: 22px;"><li style="font-size: 12px; background-color: white; font-family: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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, &#39; -&gt; &#39;, w, h</li><li style="font-size: 12px; background-color: white; font-family: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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,  &#39;screencapture.bmp&#39;)</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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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&#39;t find a wx function to get these</li><li style="font-size: 12px; background-color: white; font-family: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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: &#39;Courier New&#39;,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(&quot;screencapture.bmp&quot;, wx.BITMAP_TYPE_BMP)</li><li style="font-size: 12px; background-color: white; font-family: &#39;Courier New&#39;,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(&quot;screencapture.jpg&quot;, wx.BITMAP_TYPE_JPEG)</li><li style="font-size: 12px; background-color: white; font-family: &#39;Courier New&#39;,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(&quot;screencapture.png&quot;, wx.BITMAP_TYPE_PNG)</li></ol></span><br clear="all"><br>-- <br><font color="#888888"><font color="#000099"><b>Josu Rodriguez Vilda</b></font><div><font color="#000099"><b><br>
</b></font></div></font></blockquote><div> <br>Lo he visto en [1]<br>Con esto sí que parece funcionar (lo he probado con notepad++ abierto y con la ventana buscar abierta):<br><br>&gt;&gt;&gt; import sys<br>&gt;&gt;&gt; from PyQt4.QtGui import QPixmap, QApplication<br>
&gt;&gt;&gt; app = QApplication(sys.argv)<br>&gt;&gt;&gt; QPixmap.grabWindow(QApplication.desktop().winId()).save(&#39;test.png&#39;,&#39;png&#39;)<br><br>pero necesitas tener instalado PyQt4.<br><br>La segunda opción que ponen en [1] no me ha funcionado y ocurre lo que tú dices, no graba la ventana buscar de notepad++:<br>
<br>&gt;&gt;&gt; import ImageGrab<br>&gt;&gt;&gt; img = ImageGrab.grab()<br>&gt;&gt;&gt; img.save(&#39;test.jpg&#39;, &#39;JPEG&#39;)<br><br>[1] <a href="http://es.w3support.net/index.php?db=so&amp;id=69645">http://es.w3support.net/index.php?db=so&amp;id=69645</a><br>
</div></div>