【问题标题】:Get layer attributes from xcf (GIMP) files C#从 xcf (GIMP) 文件 C# 获取图层属性
【发布时间】:2020-01-09 10:56:41
【问题描述】:

不久前我发现了一些 C# 代码,它帮助我从 XCF 文件中获取各个层的详细信息。我目前可以提取图层“x”、“y”、“图层名称”以及“图层 x”和“图层 y”的详细信息。现在我想要图层颜色、内容和旋转值(如果旋转)以及可能的任何其他细节。有人可以帮忙吗?

我的代码:

    private void Form1_Load(object sender, EventArgs e)
    {
        string inputPdf  = image_path + "offical_tour.xcf"; // GIMP file to load
        string outputPng = image_path + "output.png";       // output filename


        using (MagickImageCollection images = new MagickImageCollection(inputPdf))
        {
            int i = 0;

            foreach (var image in images)
            {
                if (i > 0)
                {
                    string layerFile = Path.Combine(image_path, image.Label + $".png");

                    image.Write(layerFile); // save the individual layers

                    // show some layer attributes
                    Console.WriteLine(image.Page.X + " x " + image.Page.Y + " = Layer:'" + image.Label + "' -- " + image.Width + " -- " + image.Height);
                }

                if (i++ == 0 || image.Compose != CompositeOperator.Over) continue;
            }
        }
    }

【问题讨论】:

  • 没有像AFAIK层的“旋转”这样的东西(除了可能是前文本层)。 “颜色”是 UI 中的标签颜色吗?
  • 困惑 - 我有一个图层(c# 被视为“标签”),它在 GIMP 中可以旋转,具有颜色和字体类型等。我不敢相信无法提取这些细节,并且在保存到单独的文件之前更新它们??

标签: c# file attributes gimp


【解决方案1】:

您寻找的信息作为图层的“寄生虫”保存在 Gimp 中,例如:

(text "aaaa")
(font "Roboto Heavy")
(font-size 60)
(font-size-unit pixels)
(antialias yes)
(language "cad")
(base-direction ttb-rtl)
(color (color-rgb 0 0 0))
(justify center)
(box-mode dynamic)
(box-unit pixels)
(hinting yes)

这是一个类似 JSON 的对象(但使用 LISP/Scheme 语法)。从 Gimp 2.10 开始,如果文本的特定部分具有特定格式,则 text 元素可以改为 markup 元素:

(markup "<markup>plain<i>italic</i><b>bold</b></markup>")

当然,我不知道你们的图书馆是如何检索这些信息的……

【讨论】:

  • 感谢分享,但我有点不确定如何将(如果这是正确的话)集成到 C# 中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多