transfer image from extension dll to wx.Image

Hi,

I am trying to transfer an image from extension dll to
wx.Image. I was able to tranfer using python string
data type (make a copy first) and use wx.Image.SetData
method to copy the image again to an wx.Image.
However, attempts to transfer using python buffer data
type (no copying) and use wx.Image.SetDataBuffer
method have always result in an exception and exit of
program. attached is the dll and python code. Anyone
know why?

Thanks,

Fuming Wang

extension code:

int length = 30000;

static PyObject *
spam_GetImageData(PyObject *self)
{
    int i, width;

    buffer = (unsigned char *) malloc(length *
sizeof(unsigned char));

    for (i=0; i<length; ++i) {
        buffer[i] = (unsigned char) 127;
    }

    return Py_BuildValue("s#ii", buffer, length,
width, width);
};

static PyObject *
spam_GetImageBuffer(PyObject *self)
{
    int i;

    buffer = (unsigned char *) malloc(length *
sizeof(unsigned char));

    for (i=0; i<length; ++i) {
        buffer[i] = (unsigned char) 127;
    }

    return PyBuffer_FromMemory(buffer, length);
};

Python code:

import wx
import spam

wx.InitAllImageHandlers()
data, width, height = spam.GetImageData()
im = wx.EmptyImage(100, 100)
im.SetData(data)
# ok

buffer = spam.GetImageBuffer()
im2 = wx.EmptyImage(100, 100)
im.SetDataBuffer(buffer)
# exception and exit of program

···

__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree

Hi,

I forgot to mention. This was run on Windows2000 with
python 2.3 and wxPython 2.4.1.2. Extension is
compiled with VC++ 6.0 and disutil.py

Thanks,
Fuming

···

--- Fuming Wang <fumingw@yahoo.com> wrote:

Hi,

I am trying to transfer an image from extension dll
to
wx.Image. I was able to tranfer using python string
data type (make a copy first) and use
wx.Image.SetData
method to copy the image again to an wx.Image.
However, attempts to transfer using python buffer
data
type (no copying) and use wx.Image.SetDataBuffer
method have always result in an exception and exit
of
program. attached is the dll and python code.
Anyone
know why?

Thanks,

Fuming Wang

extension code:

int length = 30000;

static PyObject *
spam_GetImageData(PyObject *self)
{
    int i, width;

    buffer = (unsigned char *) malloc(length *
sizeof(unsigned char));

    for (i=0; i<length; ++i) {
        buffer[i] = (unsigned char) 127;
    }

    return Py_BuildValue("s#ii", buffer, length,
width, width);
};

static PyObject *
spam_GetImageBuffer(PyObject *self)
{
    int i;

    buffer = (unsigned char *) malloc(length *
sizeof(unsigned char));

    for (i=0; i<length; ++i) {
        buffer[i] = (unsigned char) 127;
    }

    return PyBuffer_FromMemory(buffer, length);
};

Python code:

import wx
import spam

wx.InitAllImageHandlers()
data, width, height = spam.GetImageData()
im = wx.EmptyImage(100, 100)
im.SetData(data)
# ok

buffer = spam.GetImageBuffer()
im2 = wx.EmptyImage(100, 100)
im.SetDataBuffer(buffer)
# exception and exit of program

__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
Yahooist Teil der Yahoo Markenfamilie

__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard

Fuming Wang wrote:

Hi,

I am trying to transfer an image from extension dll to
wx.Image. I was able to tranfer using python string
data type (make a copy first) and use wx.Image.SetData
method to copy the image again to an wx.Image. However, attempts to transfer using python buffer data
type (no copying) and use wx.Image.SetDataBuffer
method have always result in an exception and exit of
program. attached is the dll and python code. Anyone
know why?

There are a couple bugs in SetDataBuffer, I'll check in a fix shortly.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!