logo       

Re: GDI+ with ctypes: msg#00034

python.ctypes

Subject: Re: GDI+ with ctypes

Florian Schulze <florian.proff.schulze@xxxxxxx> writes:

> Hi!
>
> Is it possible to access GDI+ with ctypes and if that's the case, can
> someone give me a hint how to do that?

Although GDI+ is a C++ library, you can access it with ctypes. The
platform SDK has a GdiPlusFlat.h file, which contains a lot of function
definitions for C code.

Then, there is also a gdiplus type library for gdiplus, which I found
somewhere on the internet. The readtlb tool, included with ctypes, can
be run on this typelib to create a module containing all the enum and
structure definitions you may need. With the readtlb output piped into
a gdiplus.py module, I was able to write this code, which prints the
width and height of a jpg file:

<code>
from ctypes import *
import gdiplus

gdip = windll.gdiplus

i = gdiplus.GdiplusStartupInput()
o = gdiplus.GdiplusStartupOutput()

token = c_ulong()
i.GdiplusVersion = 1
print gdip.GdiplusStartup(byref(token), byref(i), byref(o))

pout = c_int()

print gdip.GdipLoadImageFromFile(ur"c:\sf\ctypes\py2exe.jpg", byref(pout))
width = c_uint()
print gdip.GdipGetImageWidth(pout, byref(width))
print "Width", width
print gdip.GdipGetImageHeight(pout, byref(width))
print "Height", width
gdip.GdipDisposeImage(pout);

print gdip.GdiplusShutdown(token)
</code>

Thomas



-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise