English 中文(简体)
通过SWIG代理标,作为对PIL.Image的投入。
原标题:Passing a SWIG proxy object as input to PIL.Image.frombuffer

I m 采用SWIGarray_nal 在Krays.i中界定的宏观定义是建立一个未经签字的果园缓冲,可以送往我处理情况的项目的++方。 这项工程罚款——在照相机引发后,缓冲器填充了湿度数据,我可以用假日[]来提一下缓冲,看看它所拥有的东西。 我现在想利用<代码>Image. Frombuffer,从该缓冲带上形成一个临时自治机构的形象:

Image.frombuffer(mode, size, data) => image

(PPIL 1.1.4)。 利用标准“批量”分解器,在座标或缓冲标目中生成图象记忆。

但我收到一个错误信息,告诉我,SWIG反对I供应不是平坦的缓冲:

File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1853, in frombuffer
core.map_buffer(data, size, decoder_name, None, 0, args)
TypeError: expected string or buffer

我怎么能够使SWIG目标的代理与<代码>的缓冲类型相一致。 图像,来自

问题回答

如果你能够处理您的SWIG缓冲机的签名性问题,你可以直接创建PIL成像仪。 http://www.un.org/Depts/DGACM/index_french.htm 您将发现:

struct ImagingMemoryInstance {

    /* Format */
    char mode[4+1]; /* Band names ("1", "L", "P", "RGB", "RGBA", "CMYK") */
    int type;       /* Data type (IMAGING_TYPE_*) */
    int depth;      /* Depth (ignored in this version) */
    int bands;      /* Number of bands (1, 2, 3, or 4) */
    int xsize;      /* Image dimension. */
    int ysize;

    /* Colour palette (for "P" images only) */
    ImagingPalette palette;

    /* Data pointers */
    UINT8 **image8; /* Set for 8-bit images (pixelsize=1). */
    INT32 **image32;    /* Set for 32-bit images (pixelsize=4). */

    /* Internals */
    char **image;   /* Actual raster data. */
    char *block;    /* Set if data is allocated in a single block. */

    int pixelsize;  /* Size of a pixel, in bytes (1, 2 or 4) */
    int linesize;   /* Size of a line, in bytes (xsize * pixelsize) */

    /* Virtual methods */
    void (*destroy)(Imaging im);
};

...... 图像计量* 是Imaging 的型号,是你在整个消费物价指数C推广源中普遍发现的碎片的基础。 Don一字,看——从APIC的消息来源看,PIL的编码基础明显是可行的,相当一致。

As @maxy points out, you can also create a NumPy array struct just as easy (if not easier) -- but while the NumPy C API is as stable as out of Guido s personal playbook, I personally find that one library-source dependency is enough, in these scenarios.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签