Search code examples
bitmapvala

How to Rotate Image 90 degrees


Is there vala class that can rotate a bitmap? The way to accomplish this using C# is shown here (very slick) but the same code

public void RotateAndSaveImage(String input, String output)
{
    using (Image img = Image.FromFile(input))
    {
        img.RotateFlip(RotateFlipType.Rotate90FlipNone);
        img.Save(output, System.Drawing.Imaging.ImageFormat.Jpeg);
    }
}

in vala causes

test.vala:48.22-48.24: error: syntax error, expected `)'
        using (Image img = Image.FromFile(input))
                     ^^^

I looked through the Valadoc but could not find an image class and vala Bitmap didn't seem very useful.


Solution

  • You'd want to use a Gdk.Pixbuf, which uses the GDK+ libraries to manipulate images.

    var img = Gdk.Pixbuf.from_file(input);
    var rotate_image = img.rotate_simple(90);
    rotate_image.save(output, "jpeg");
    

    It's worth noting that Vala is not meant to be directly compatible with C#.