Image capture

Discussion in 'Python' started by Catalin Lungu, Jan 5, 2005.

  1. Hi,
    Can anybody help me to implement the following VB code in Python. Thanks in
    advance.

    Private Declare Function SendMessage Lib "user32.dll" Alias _
    "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    ByVal wParam As Long, ByVal lParam As Long) As Long

    Private Const WM_PAINT = &HF
    Private Const WM_PRINT = &H317
    Private Const PRF_CLIENT = &H4&
    Private Const PRF_CHILDREN = &H10&
    Private Const PRF_OWNED = &H20&

    Private Sub Command1_Click()
    SendMessage grid.hwnd, WM_PAINT, picture.hDC, 0
    SendMessage grid.hwnd, WM_PRINT, picture.hDC, PRF_CHILDREN Or PRF_CLIENT
    Or PRF_OWNED
    picture.Picture = picture.Image
    picture.Refresh
    End Sub


    Catalin
     
    Catalin Lungu, Jan 5, 2005
    #1
    1. Advertising

  2. Catalin Lungu

    Kartic Guest

    Catalin,

    Some explanation about what you are tring to do will be of immense
    help.

    Did you want to capture some other Windows object from Python or do you
    want to capture a Python GUI application from Python?

    I might be able to help out, but please send more details.
    Thank you,
    --Kartic
     
    Kartic, Jan 5, 2005
    #2
    1. Advertising

  3. Hi,

    I want to capture a no visible area of a wxFrame of Python. This area
    contain a wxGrid object. In VB6 this code work very good.

    Thanks.

    "Kartic" <> escribió en el mensaje
    news:...
    > Catalin,
    >
    > Some explanation about what you are tring to do will be of immense
    > help.
    >
    > Did you want to capture some other Windows object from Python or do you
    > want to capture a Python GUI application from Python?
    >
    > I might be able to help out, but please send more details.
    > Thank you,
    > --Kartic
    >
     
    Catalin Lungu, Jan 5, 2005
    #3
  4. Catalin Lungu

    Kartic Guest

    Hi Catalin,

    Here are the modifications to your code. I am emailing you the complete
    file back to your email address. Please note that you need PIL (Python
    Imaging Library) to grab the window. I included a step to save the
    image, but you can do whatever you want with it.

    Thanks,
    --Kartic

    -------------- Unified Diff ---------------

    --- Catalin.txt Wed Jan 05 11:43:38 2005
    +++ frmDesign.py Wed Jan 05 11:43:17 2005
    @@ -1,7 +1,7 @@
    from wxPython.wx import *
    from wxPython.grid import *
    from win32api import SendMessage
    -import win32ui
    +import win32ui, win32gui, ImageGrab

    WM_PAINT = 0xf
    WM_PRINT = 0x317
    @@ -47,6 +47,10 @@
    dc = wxMemoryDC()
    dc.SelectObject(bmp)
    dc.Clear()
    + win_sz = win32gui.GetWindowRect(self.grd.GetHandle())
    + print win_sz
    + im = ImageGrab.grab((win_sz[0],win_sz[1],win_sz[2],win_sz[3]))
    + im.save('C:/TEMP/grid.jpg')
    SendMessage(self.grd.GetHandle(), WM_PAINT, dc.GetHDC(), 0)
    SendMessage(self.grd.GetHandle(), WM_PRINT, dc.GetHDC(),
    PRF_CHILDREN|PRF_CLIENT|PRF_OWNED)
     
    Kartic, Jan 5, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    617
  2. kelly
    Replies:
    0
    Views:
    531
    kelly
    Feb 15, 2006
  3. tochaotic4u
    Replies:
    2
    Views:
    4,101
    tochaotic4u
    Jul 3, 2003
  4. Max
    Replies:
    7
    Views:
    9,190
  5. Replies:
    1
    Views:
    754
    Roedy Green
    Nov 29, 2005
Loading...

Share This Page