Click here to Skip to main content
13,249,035 members (44,657 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 20 Feb 2012

Execute GIMP filters in C#

, 20 Feb 2012
Rate this:
Please Sign up or sign in to vote.
How to execute GIMP filters in C#.

First of all you need to install GIMP. After that, set the path variable (C:\Program Files\GIMP-2.0\bin). Now write a GIMP script and save it with the .scm extention in the C:\Users\[username]\.gimp-2.6\scripts folder. You can write various GIMP scripts. You get details about GIMP filters from the pluginrc file in your home floder(C:\Users\dhanu-sdu\.gimp-2.6).

GIMP script for Unsharpmask filter

(define (simple-unsharp-mask filename
   (let* ((image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
          (drawable (car (gimp-image-get-active-layer image))))
     (plug-in-unsharp-mask RUN-NONINTERACTIVE
                       image drawable radius amount threshold)
     (set! drawable (car (gimp-image-get-active-layer image)))
     (gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
     (gimp-image-delete image)))

Now in the C# application, construct the command and execute in the command line:

private void unsharpMaskButton_Click(object sender, EventArgs e)
        if (!string.IsNullOrEmpty(choosenFile))
            int radius = radiusTrackBar.Value;
            int amount = amountTrackBar.Value;
            int threshold = ThresholdTrackBar.Value;
            string path = choosenFile.Replace(@"\", @"\\");
            //creating the command
            string a = @"gimp-2.6.exe -i -b ""(simple-unsharp-mask \""" + 
                   path + @"\"" " + radius + " " + amount + " " + threshold +
                   @")"" -b ""(gimp-quit 0)""";
            //execute gimp filter in command line
            string result = ExecuteCommandSync(a);
            //sets the new image as the pictureBox image
            Bitmap newImage = (Bitmap)Image.FromFile(choosenFile);
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            pictureBox1.Image = new Bitmap(newImage);
            newImage = null;
            MessageBox.Show("please select a image");
    catch (Exception a)

Executing the command

public string ExecuteCommandSync(object command) 
        System.Diagnostics.ProcessStartInfo procStartInfo =
            new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
        procStartInfo.RedirectStandardOutput = true;
        procStartInfo.UseShellExecute = false;
        procStartInfo.CreateNoWindow = true;
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.StartInfo = procStartInfo;
        StreamReader reader = proc.StandardOutput;
        string result = reader.ReadToEnd();
        return result;
    catch (Exception objException)
    return null;


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Dhanushka Madushan lk
Software Developer
Sri Lanka Sri Lanka
No Biography provided

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171114.1 | Last Updated 20 Feb 2012
Article Copyright 2012 by Dhanushka Madushan lk
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid