我一直在试验GIMP(v2.8.10)层的操作,编程地使用自定义gimpfu插件。我成功地实现了选择、旋转、缩放和平移现有层的一部分:
插件中的一些代码:
简化为相关性。所有这些指令都起作用了。
# I only use one layer in the probe image
layer = img.layers[0]
selection = pdb.gimp_rect_select(img, init_coords[0], init_coords[1],
my_width,my_height,2,0,0)
# Copy and paste selection
pdb.gimp_edit_copy(layer)
float_layer = pdb.gimp_edit_paste(layer, 1)
# Transform floating selection step by step
float_layer = pdb.gimp_item_transform_rotate_simple(float_layer,
ROTATE_90, 1, 0, 0)
float_layer = pdb.gimp_layer_scale(float_layer, new_width,new_height, 1)
float_layer = pdb.gimp_layer_translate(float_layer, h_offset, 0)问题所在
gimp_layer_translate),其他所有操作都正常。gimp_layer_scale的行,其他一切都会正常工作。gimp_layer_translate就会与RuntimeError一起崩溃。这个过程gimp层转换已经被调用了与不正确的ID层.可能是试图用一个不存在的层操作。
我不知道为什么会这样失败。如果他们各自工作,为什么不一起工作呢?我想知道。
参考文献
我通常从template.py in gimpbook.com开始作为构建插件的起点,因为它似乎有一个坚实的结构,可以将代码封装到“撤销块”中。我关于pdb的主要信息来源是我在谷歌上找到的本网站。另外,我在这个问题上找到了一些我需要的程序。
另外,我的一个以前的问题可能有助于参考如何开始为gimp定制插件。
是什么让我陷入困境
我不确定原因是gimp的错误还是我的代码被错误地实现了。由于在关联问题的答案上发布了一些代码,我想知道我是否过度使用了可用的内存(毕竟,我不知道必须使用特定的过程调用来销毁对象,直到我在这个答案上找到答案)。如果我不删除它们会怎么样?我想知道。在我关闭GIMP之前,它们会一直保存在RAM中,还是会生成将淹没GIMP系统的持久文件?老实说,我不知道忽视这个问题的后果。
发布于 2016-01-15 10:21:30
在使用该层时,移除分配。下面是如何销毁float_layer变量:
# This creates a new layer that you assign to the float_layer
float_layer = pdb.gimp_item_transform_rotate_simple(float_layer,
ROTATE_90, 1, 0, 0)
# This does not return anything at all, it works with the layer in-place.
# But you overwrite the float_layer variable anyway, destroying it.
float_layer = pdb.gimp_layer_scale(float_layer, new_width,new_height, 1)
# This does not work because float_layer is no longer referencing the layer at all
float_layer = pdb.gimp_layer_translate(float_layer, h_offset, 0)因此,可以这样做:
float_layer = pdb.gimp_item_transform_rotate_simple(float_layer,
ROTATE_90, 1, 0, 0)
pdb.gimp_layer_scale(float_layer, new_width,new_height, 1)
pdb.gimp_layer_translate(float_layer, h_offset, 0)发布于 2016-01-14 17:03:34
在执行这两个函数之前,我通过将floating_layer切换到一个新的Layer实例来修正它。
fixed_layer = gimp.Layer(img, 'float_layer', int(gh), int(gw),
RGBA_IMAGE, 100, 1)因此,我做了以下组合:
# Transform floating selection step by step
float_layer = pdb.gimp_item_transform_rotate_simple(float_layer,
ROTATE_90, 1, 0, 0)
fixed_layer = gimp.Layer(img, 'float_layer', new_width, new_height,
RGBA_IMAGE, 100, 1)
fixed_layer = pdb.gimp_layer_scale(float_layer, new_width,new_height, 1)
fixed_layer = pdb.gimp_layer_translate(float_layer, h_offset, 0)问题似乎是,在该层上执行了一些过程之后,它就变成了None (就像它被自动从内存中删除.)。这个解决方案允许我再执行2到3个操作..。这不是一个完整的解决方案。我会继续研究
https://stackoverflow.com/questions/34779837
复制相似问题