2

我正在编写一个插件脚本,它将打开一个文件,按颜色选择,将选择更改为新颜色,将图像另存为新文件。

我不知道如何将颜色更改为新颜色。有人可以提供指导吗?

这是我到目前为止所拥有的:

  # open input file
  theImage = pdb.gimp_file_load(in_filename, in_filename)

  # get the active layer
  drawable = pdb.gimp_image_active_drawable(theImage)

  # select everything in the image with the color that is to be replaced
  pdb.gimp_image_select_color(theImage, CHANNEL_OP_REPLACE, drawable, colorToReplace)

  # need to do something to change the color from colorToReplace to the newColor
  # but I have no idea how to change the color.

  # merge the layers to maintain transparency
  layer = pdb.gimp_image_merge_visible_layers(theImage, CLIP_TO_IMAGE)

  # save the file to a new filename
  pdb.gimp_file_save(theImage, layer, out_filename, out_filename)
4

1 回答 1

1

您只需要填充选择:

pdb.gimp_drawable_edit_fill(drawable, fill_type)

这会用当前的前景色/背景色填充选区(取决于 fill_type)。如果您需要在插件中设置此颜色:

import gimpcolor

color=gimpcolor.RGB(0,255,0)  # integers in 0->255 range)
color=gimpcolor.RGB(0.,1.,0.) # Floats in 0.->1. range)

pdb.gimp_context_set_foreground(color)

请注意,这回答了您的技术问题,但这很可能不是您想要做的(像素化边缘、剩余光环等)。好的技术通常是用透明度(在Color Erase模式中绘制)替换初始颜色,然后在模式中用新颜色填充孔Behind。例如,用 BG 替换 FG 颜色:

pdb.gimp_edit_bucket_fill(layer,FG_BUCKET_FILL,COLOR_ERASE_MODE,100.,0.,0,0.,0.)
pdb.gimp_edit_bucket_fill(layer,BG_BUCKET_FILL,BEHIND_MODE, 100.,0.,0,0.,0.)

如果您不想更改图像中的其他混合颜色,请保留颜色选择,在应用两个绘制操作之前将其增大一个像素。增加选择使上述操作适用于边缘上的像素,这才是真正重要的地方。

于 2020-03-26T13:54:55.707 回答