Re: Saving a Device context (DC) into a picture file
Michael C <[email protected]> Sat, 22 Apr 2017 12:15:39 -0700
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <CANyKM1h9vwRvg6DXn=XxS40yhKic+Rq5K-5vN+zsuyk+CWaZzg@mail.gmail.com> |
--===============0569635284057066995== Content-Type: multipart/alternative; boundary=001a1141f01c140b04054dc63376 --001a1141f01c140b04054dc63376 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Never mind, I found this https://books.google.ca/books?id=3D9MS9BQAAQBAJ&pg=3DPA116&lpg=3DPA116&dq= =3Dpython+device+context+save&source=3Dbl&ots=3DtYhl4K1K6J&sig=3DzgzJmOFeOI= ZL2C5eGrZ-Oa_QRB4&hl=3Den&sa=3DX&ved=3D0ahUKEwijjIvX37jTAhVQ42MKHVIFCHEQ6AE= IOjAE#v=3Donepage&q=3Dpython%20device%20context%20save&f=3Dfalse thanks all On Sat, Apr 22, 2017 at 11:52 AM, Michael C <[email protected]= > wrote: > Quick Question: > I am using this code, and I have tried to find answers with google, and I > have read through MSDN. > > How do I save the DC into a png file or bmp? > > thanks! > > > import time > import ctypes > ##from ctypes import * > ## I don't like this. I like to import. > > time.sleep(2) > > # Set up the User32 and GDI32 > User32 =3D ctypes.WinDLL('User32', use_last_error=3DTrue) > GDI32 =3D ctypes.WinDLL('GDI32', use_last_error=3DTrue) > > # Set up Fx to be used. > GetForegroundWindow =3D User32.GetForegroundWindow > GetWindowDC =3D User32.GetWindowDC > GetPixel =3D GDI32.GetPixel > ReleaseDC =3D User32.ReleaseDC > > > # main code > foreground_window =3D GetForegroundWindow() > dc =3D GetWindowDC(foreground_window) > > # set timer to see how fast it runs. > t0 =3D time.clock() > > for i in range(50): > rgb =3D GetPixel(dc, 10, 10) > #print(rgb) > r =3D rgb & 0xff > g =3D (rgb >> 8) & 0xff > b =3D (rgb >> 16) & 0xff > ## print("RGB(%d, %d, %d)" % (r, g, b)) > > print(time.clock() - t0) > ReleaseDC(foreground_window, dc) > > --001a1141f01c140b04054dc63376 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Never mind, I found this<div><a href=3D"https://books.goog= le.ca/books?id=3D9MS9BQAAQBAJ&pg=3DPA116&lpg=3DPA116&dq=3Dpytho= n+device+context+save&source=3Dbl&ots=3DtYhl4K1K6J&sig=3DzgzJmO= FeOIZL2C5eGrZ-Oa_QRB4&hl=3Den&sa=3DX&ved=3D0ahUKEwijjIvX37jTAhV= Q42MKHVIFCHEQ6AEIOjAE#v=3Donepage&q=3Dpython%20device%20context%20save&= amp;f=3Dfalse">https://books.google.ca/books?id=3D9MS9BQAAQBAJ&pg=3DPA1= 16&lpg=3DPA116&dq=3Dpython+device+context+save&source=3Dbl&= ots=3DtYhl4K1K6J&sig=3DzgzJmOFeOIZL2C5eGrZ-Oa_QRB4&hl=3Den&sa= =3DX&ved=3D0ahUKEwijjIvX37jTAhVQ42MKHVIFCHEQ6AEIOjAE#v=3Donepage&q= =3Dpython%20device%20context%20save&f=3Dfalse</a><br></div><div><br></d= iv><div>thanks all</div></div><div class=3D"gmail_extra"><br><div class=3D"= gmail_quote">On Sat, Apr 22, 2017 at 11:52 AM, Michael C <span dir=3D"ltr">= <<a href=3D"mailto:[email protected]" target=3D"_blank">mys= [email protected]</a>></span> wrote:<br><blockquote class=3D"g= mail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-l= eft:1ex"><div dir=3D"ltr">Quick Question:<div>I am using this code, and I h= ave tried to find answers with google, and I have read through MSDN.</div><= div><br></div><div>How do I save the DC into a png file or bmp?</div><div><= br></div><div>thanks!</div><div><br></div><div><br></div><div><div>import t= ime</div><div>import ctypes</div><div>##from ctypes import *</div><div>## I= don't like this. I like to import.</div><div><br></div><div>time.sleep= (2)</div><div><br></div><div># Set up the User32 and GDI32</div><div>User32= =3D ctypes.WinDLL('User32', use_last_error=3DTrue)</div><div>GDI32= =3D ctypes.WinDLL('GDI32', use_last_error=3DTrue)</div><div><br></= div><div># Set up Fx to be used.</div><div>GetForegroundWindow =3D User32.G= etForegroundWindow</div><div>GetWindowDC =3D User32.GetWindowDC</div><div>G= etPixel =3D GDI32.GetPixel</div><div>ReleaseDC =3D User32.ReleaseDC</div><d= iv><br></div><div><br></div><div># main code</div><div>foreground_window = =3D GetForegroundWindow()</div><div>dc =3D GetWindowDC(foreground_window)</= div><div><br></div><div># set timer to see how fast it runs.</div><div>t0 = =3D time.clock()</div><div><br></div><div>for i in range(50):</div><div>=C2= =A0 =C2=A0 rgb =3D GetPixel(dc, 10, 10)</div><div>=C2=A0 =C2=A0 #print(rgb)= </div><div>=C2=A0 =C2=A0 r =3D rgb & 0xff</div><div>=C2=A0 =C2=A0 g =3D= (rgb >> 8) & 0xff</div><div>=C2=A0 =C2=A0 b =3D (rgb >> 16= ) & 0xff</div><div>## =C2=A0 =C2=A0print("RGB(%d, %d, %d)" % = (r, g, b))</div><div><br></div><div>print(time.clock() - t0)</div><div>Rele= aseDC(foreground_window, dc)</div></div><div><br></div></div> </blockquote></div><br></div> --001a1141f01c140b04054dc63376-- --===============0569635284057066995== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot --===============0569635284057066995== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ ctypes-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ctypes-users --===============0569635284057066995==--