Saving a Device context (DC) into a picture file
Michael C <[email protected]> Sat, 22 Apr 2017 11:52:30 -0700
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <CANyKM1jm9tUtHRA-t3PwJyvrkTLfcVEY=8gyCPd2vsM_ztdECA@mail.gmail.com> |
--===============2555449647950185566==
Content-Type: multipart/alternative; boundary=001a11c142104a3ff5054dc5e05f
--001a11c142104a3ff5054dc5e05f
Content-Type: text/plain; charset=UTF-8
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 = ctypes.WinDLL('User32', use_last_error=True)
GDI32 = ctypes.WinDLL('GDI32', use_last_error=True)
# Set up Fx to be used.
GetForegroundWindow = User32.GetForegroundWindow
GetWindowDC = User32.GetWindowDC
GetPixel = GDI32.GetPixel
ReleaseDC = User32.ReleaseDC
# main code
foreground_window = GetForegroundWindow()
dc = GetWindowDC(foreground_window)
# set timer to see how fast it runs.
t0 = time.clock()
for i in range(50):
rgb = GetPixel(dc, 10, 10)
#print(rgb)
r = rgb & 0xff
g = (rgb >> 8) & 0xff
b = (rgb >> 16) & 0xff
## print("RGB(%d, %d, %d)" % (r, g, b))
print(time.clock() - t0)
ReleaseDC(foreground_window, dc)
--001a11c142104a3ff5054dc5e05f
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Quick Question:<div>I am using this code, and I have 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 time</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 ctyp=
es.WinDLL('User32', use_last_error=3DTrue)</div><div>GDI32 =3D ctyp=
es.WinDLL('GDI32', use_last_error=3DTrue)</div><div><br></div><div>=
# Set up Fx to be used.</div><div>GetForegroundWindow =3D User32.GetForegro=
undWindow</div><div>GetWindowDC =3D User32.GetWindowDC</div><div>GetPixel =
=3D GDI32.GetPixel</div><div>ReleaseDC =3D User32.ReleaseDC</div><div><br><=
/div><div><br></div><div># main code</div><div>foreground_window =3D GetFor=
egroundWindow()</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.cl=
ock()</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 >&=
gt; 8) & 0xff</div><div>=C2=A0 =C2=A0 b =3D (rgb >> 16) & 0xf=
f</div><div>## =C2=A0 =C2=A0print("RGB(%d, %d, %d)" % (r, g, b))<=
/div><div><br></div><div>print(time.clock() - t0)</div><div>ReleaseDC(foreg=
round_window, dc)</div></div><div><br></div></div>
--001a11c142104a3ff5054dc5e05f--
--===============2555449647950185566==
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
--===============2555449647950185566==
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
--===============2555449647950185566==--