1

我正在尝试用 Gimp 自动完成绘制线条的任务。

所以我尝试了脚本功能,到目前为止没有运气。


    >>>from pprint import pprint
    >>>img = gimp.Image(200, 200, RGB)
    >>>pprint (pdb.gimp_pencil.params)
    ((16, 'drawable', 'The affected drawable'), 
     (0,
       'num-strokes',
       'Number of stroke control points (count each coordinate as 2 points) (num-strokes >= 2)'),
     (8,
       'strokes',
       'Array of stroke coordinates: { s1.x, s1.y, s2.x, s2.y, ..., sn.x, sn.y }'))
    >>>pdb.gimp_pencil(img, 4, [0,0,200,200] )
    Traceback (most recent call last):
      File "<input>", line 1, in <module>
    TypeError: wrong parameter type

我找不到任何在 Python 中为 Gimp 传递向量(笔画坐标数组)的示例

这里有什么问题?

4

1 回答 1

2

好吧,我的错误,我认为 TypeError 在最后一个数组参数上。碰巧img不是可绘制的,因此是TypeError。

你必须:

  1. 创建图像
  2. 创建一个图层
  3. 将图层添加到图像
  4. 设置图层激活
  5. 获取图像的活动drawable

那么只有你可以在方法中使用这个drawable gimp_pencil()

img = gimp.Image(200, 200, RGB)
layer = gimp.Layer(img, "Test", 200, 200, RGBA_IMAGE, 100, NORMAL_MODE)
img.add_layer(layer, -1)
pdb.gimp_image_set_active_layer(img, layer)
draw = pdb.gimp_image_get_active_drawable(img)
pdb.gimp_pencil(draw, 4, [0,0,100,100])
disp1 = gimp.Display(img)
于 2014-05-21T00:14:58.600 回答