×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    31

    Problems with a python wrapper: convert PyObject to Image

    Hi all!
    I hope that somebody can help because I am stuck on a project!

    From Python, I need to call some C++ code that modifies an image and returns it. I am able to write the wrapper so that it converts correctly from Python to C++ but I am not able to do the opposite. I don't know much about Python so the mistake might be really stupid.

    The relevant part of the wrapper:

    Code:
    static PyObject* FunctionName(PyObject* self, PyObject* args){
    
    CFbsBitmap *image;
    PyObject *input;
    
    if (!PyArg_ParseTuple(args, "O", &input1)) {
      return Py_BuildValue("s", "Cannot parse arguments.");
    }
        
    // Check if the call was made on a python object
    if (!PyCObject_Check(input1) || !PyCObject_Check(input2)) {
        return Py_BuildValue("i", -1);
    }
    
    // Turn PyCObject into CFbsBitmap
    image = (CFbsBitmap *)PyCObject_AsVoidPtr(input);
    
    //here call some C++ code on image
    
    // From here on I am not sure it is correct
    PyObject *pyObj;
    pyObj = (PyObject *)PyCObject_FromVoidPtr(image, NULL);
    return pyObj;
    so now, from Python, I call:

    Code:
    imOut = wrapper.FunctionName(PyImage._bitmapapi())
    Everything works but now imOut is a PyCObject at 0x.... and I don't know how to convert it back to an image.

    Any idea? Even the reference to some useful documentation would be helpful: where I looked there wasn't even a mention for _bitmapapi().
    PLEASE!!
    Thanks,
    Pdcb



    PS: sorry for the double posting but I hit post by mistake and I wasn't able to delete the post
    Last edited by pdcb_pdcb; 2008-03-11 at 04:33.

  2. #2
    Registered User
    Join Date
    Nov 2007
    Posts
    31

    Re: Problems with a python wrapper: convert PyObject to Image

    I just realized that there is an undocumented method that changes the PyCObject to a graphics.Image object:

    Code:
    myPyObj = wrapper.FunctionName(PyImage._bitmapapi())
    im = Image.from_cfbsbitmap(myPyObj)
    It seems to work.

    Thank a lot,
    Pdcb
    Last edited by pdcb_pdcb; 2008-03-11 at 05:37.

Similar Threads

  1. --- ???save image problem??? ---
    By ferenn in forum Mobile Java Media (Graphics & Sounds)
    Replies: 6
    Last Post: 2007-10-01, 14:33
  2. image and animation problems....
    By antonio5982 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 4
    Last Post: 2007-04-17, 01:15
  3. Is there any ProgressBar wrapper for python?
    By papit01 in forum Symbian
    Replies: 0
    Last Post: 2006-03-11, 19:29
  4. CodeWarrior COM problems (Python)
    By huoneusto in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2005-06-16, 20:28
  5. How can i manage image with python
    By darly in forum Symbian
    Replies: 1
    Last Post: 2005-02-16, 09:14

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×