This is a mirror of official site: http://jasper-net.blogspot.com/

Execute GIMP filters in C#

| Thursday, February 23, 2012
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
                             radius
                             amount
                             threshold)
   (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)
{
    try
    {
        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.Dispose();
            newImage = null;
        }
        else
        {
            MessageBox.Show("please select a image");
        }
    }
    catch (Exception a)
    {
        MessageBox.Show(a.ToString());
    }
}

Read more: Codeproject
QR: Inline image 1

Posted via email from Jasper-net

0 comments: