Pointer to Image

Thomas Heller theller at python.net
Tue Oct 19 11:18:58 EDT 2004


cjankowski at hbr-inc.com (Chris Jankowski) writes:

> Hi all,
> I am still new to using Python, so bare with me.  I am trying to call
> a DLL from my program to use some of it's functions.  The only
> parameter is supposed to be a pointer to an image.  I have tried
> several variations on passing this parameter to the DLL and I am not
> having much luck.  This is going to call other functions later for
> OCR, but I want to get a simple one working first.
>
> Here is my code:  (Very basic)
>
> from ctypes import *
> import Image
>
> myOcr = windll.LoadLibrary('ocrdll.dll') # my DLL
>
> mySize = myOcr.GetImgBitmapSize ## load the function
>
> im = Image.open('C:\\chris.tif') ## load the Image
> print id(im)  ## for testing print address of im
>
> ##myFile = c_char_p(id(im))  # I have tried several variations of this
>
> x = mySize(myFile)  ##  Actual call to the DLL Function
>                     ##  documentation only one parameter passed
> pointer to Image
>                     ##  Must be DIB Image(Device Independent Bitmap)
>                     ##  (could this be the problem?)
> Thanks for the help.

I assume the Image function you import in the code above is from PIL?
In this case, it cannot work.  You cannot take the address (id) of an
arbitrary Python object, and assume that it points to C compatible data.
Maybe you should use a function from the dll to load the image data, or
you can read the file's bytes into python string, and pass that.

Thomas



More information about the Python-list mailing list