我整天都在努力运行这段代码,但没有机会。我想在图像上执行 GIMP 过滤器,稍后将其保存到某个路径。使用此代码:
string choosenFile = "D:\here\is\the\image";
string gimpFile = "D:\here\is\my\gimp exe";
void seamlessFilter() {
try {
if (!string.IsNullOrEmpty(choosenFile)) {
string a = @"-b ""(script-fu-tile """
+ choosenFile
+ "100 100 0 TRUE 70"
+ @")"" -b ""(gimp-quit 0)""";
string result = ExecuteCommandSync(a);
Texture2D newTex = loadImage (new Vector2(200, 200), Path.GetFullPath(choosenFile));
newTex = null;
} else {
UnityEngine.Debug.Log("Please select a image");
}
} catch (Exception ex){
UnityEngine.Debug.Log (ex.ToString ());
}
}
public string ExecuteCommandSync(string command) {
ProcessStartInfo processStartInfo = new ProcessStartInfo (gimpFile, command);
processStartInfo.RedirectStandardOutput = true;
processStartInfo.UseShellExecute = false;
processStartInfo.CreateNoWindow = true;
Process process = new Process ();
process.StartInfo = processStartInfo;
process.Start ();
StreamReader reader = process.StandardOutput;
string result = reader.ReadToEnd ();
Console.WriteLine (result);
return result;
}
我尝试执行过滤器,但每次出现错误时都出现无法读取字符串的错误。这是 .scm:
`
(define (script-fu-tile img
drawable
blend-x
blend-y
overlap
square)
(let*
(
(sel-float1 0)
(sel-float2 0)
(sel-float3 0)
(sel-float4 0)
(high-pass-layer 0)
(yoffset 0)
(img-w (/ (car (gimp-image-width img)) 2))
(img-h (/ (car (gimp-image-height img)) 2))
;(newimg (car (gimp-image-new (- (car (gimp-image-width img)) blend-x)
(- (car (gimp-image-height img)) blend-y) RGB)))
)
(if (= square 1)
(set! yoffset (+ (- (* (- img-w img-h) 2) (- blend-x blend-y)) overlap))
(set! yoffset overlap)
)
(gimp-undo-push-group-start img)
(gimp-rect-select img 0 0 img-w img-h CHANNEL-OP-REPLACE FALSE 0)
(gimp-edit-copy drawable)
(set! sel-float1 (car (gimp-edit-paste drawable FALSE)))
(gimp-floating-sel-to-layer sel-float1)
(gimp-layer-translate sel-float1 (- (- img-w blend-x) yoffset) (- (- img-h blend-y) overlap))
(gimp-rect-select img img-w 0 img-w img-h CHANNEL-OP-REPLACE FALSE 0)
(gimp-edit-copy drawable)
(set! sel-float2 (car (gimp-edit-paste drawable FALSE)))
(gimp-floating-sel-to-layer sel-float2)
(gimp-layer-translate sel-float2 (- 0 img-w) (- (- img-h blend-y) overlap))
(gimp-rect-select img 0 img-h img-w img-h CHANNEL-OP-REPLACE FALSE 0)
(gimp-edit-copy drawable)
(set! sel-float3 (car (gimp-edit-paste drawable FALSE)))
(gimp-floating-sel-to-layer sel-float3)
(gimp-layer-translate sel-float3 (- (- img-w blend-x) yoffset) (- 0 img-h))
(gimp-rect-select img img-w img-h img-w img-h CHANNEL-OP-REPLACE FALSE 0)
(gimp-edit-copy drawable)
(set! sel-float4 (car (gimp-edit-paste drawable FALSE)))
(gimp-floating-sel-to-layer sel-float4)
(gimp-layer-translate sel-float4 (- 0 img-w) (- 0 img-h))
(gimp-rect-select img (- 0 blend-x) (- 0 blend-x) (+ img-w (/ blend-x 2)) (+ img-h (+ blend-x blend-x)) CHANNEL-OP-REPLACE TRUE (/ blend-x 1.68))
(gimp-selection-invert img)
(gimp-edit-clear sel-float4)
(gimp-rect-select img (- 0 blend-y) (- 0 blend-y) (+ img-w (+ blend-y blend-y)) (+ img-h (/ blend-y 2)) CHANNEL-OP-REPLACE TRUE (/ blend-y 1.68))
(gimp-selection-invert img)
(gimp-edit-clear sel-float4)
(gimp-rect-select img (- (- img-w (- blend-x blend-y)) yoffset) (- 0 blend-y) (+ img-w (+ blend-y blend-y)) (+ img-h (/ blend-y 2)) CHANNEL-OP-REPLACE TRUE (/ blend-y 1.68))
(gimp-selection-invert img)
(gimp-edit-clear sel-float3)
(gimp-rect-select img (- 0 blend-x) (- (- img-h (+ blend-x blend-y)) overlap) (+ img-w (/ blend-x 2)) (+ img-h (+ blend-x blend-x)) CHANNEL-OP-REPLACE TRUE (/ blend-x 1.68))
(gimp-selection-invert img)
(gimp-edit-clear sel-float2)
(gimp-selection-none img)
;(gimp-layer-delete drawable)
(gimp-image-crop img (- (- (* img-w 2) blend-x) yoffset) (- (- (* img-h 2) blend-y) overlap) 0 0)
; Complete the undo group
(gimp-undo-push-group-end img)
; Flush output
(gimp-displays-flush)
)
)
(script-fu-register "script-fu-tile"
"<Image>/Filters/Map/Tileable..."
"Make seamless texture"
"Pavel aka RPG Roshchin <rpg89@post.ru>"
"Pavel aka RPG Roshchin"
"2011"
"RGB*, GRAY*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Layer to blur" 0
SF-ADJUSTMENT "Blend x" '(100 0 1000 1 10 0 0)
SF-ADJUSTMENT "Blend y" '(100 0 1000 1 10 0 0)
SF-ADJUSTMENT "Overlap" '(0 0 1000 1 10 0 0)
SF-TOGGLE
"Make square texture" TRUE
;SF-ADJUSTMENT "Homogenize brightness (%)" '(70 0 100 1 10 0 0)
)`
如果有人能帮忙,我会很开心,因为我绝望了。谢谢!
也许去这里看看并尝试一下这种方法
但从事情的外观来看,你:
string a = @"-b ""(script-fu-tile """
+ choosenFile
+ "100 100 0 TRUE 70"
+ @")"" -b ""(gimp-quit 0)""";
应该看起来更像这样:
string a = @"gimp-2.6.exe -i -b ""(script-fu-tile """ +
choosenFile + @"""0 100 100 0 TRUE 70)"" -b ""(gimp-quit 0)""";
或者本质上:
string draw = "0";
string blendx = "100";
string blendy = "100";
string overlap = "0";
string sqrText = "TRUE";
string adjBright = "70";
string a = @"gimp-2.6.exe -i -b ""(simple-unsharp-mask """ +
path + @""" " + draw + " " + blendx + " " + blendy + " " + overlap + " "+ sqrText + " " + adjBright +
@")"" -b ""(gimp-quit 0)""";
从您提供的错误所说的内容来看,您的代码中的上述字符串存在问题。试试这几个人,然后给我评论。
我自己想通了 - 问题是,第一个参数 img 需要一个对象,但我写了一个字符串作为第一个参数。所以我编辑了我的 scm 脚本以将对象包装为字符串,效果很好。