1
Reply

Rotate and Save image in C#

Martyn Ball

Martyn Ball

Jul 24 2013 6:38 PM
5.4k
I had a script in ASP.NET which would rotate and save an image, I thought the language was the same and i'm having issues using the ASP.NET page so instead i'm creating a command line program to rotate the images and save them. 

For some reason though i'm getting errors on the following code, ignore the last section of the code just concentrate on the errors. 

[code]
using System;
using System.Drawing;

namespace rotate
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length >= 2)
            {
                string url = args[0];
                string rotateAmount = args[1];

                string path = "image1.jpg";

                //create an image object from the image in that path
                System.Drawing.Image img = System.Drawing.Image.FromFile(path);

                //Rotate the image in memory
                img.RotateFlip(RotateFlipType.Rotate90FlipNone);

                //Delete the file so the new image can be saved
                System.IO.File.Delete(path);

                //save the image out to the file
                img.Save(path);

                //release image file
                img.Dispose();

                // Wait for user to acknowledge the results.
                Console.WriteLine(url + " " + rotateAmount);

                Console.WriteLine("Press any key to quit!");
                Console.Read();
            }
        }
    }
}
[code]

Errors:
[code]
Error 1 The type or namespace name 'Image' does not exist in the namespace 'System.Drawing' (are you missing an assembly reference?) c:\users\martyn ball\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs 18 32 ConsoleApplication1
Error 2 The type or namespace name 'Image' does not exist in the namespace 'System.Drawing' (are you missing an assembly reference?) c:\users\martyn ball\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs 18 59 ConsoleApplication1
Error 3 The name 'RotateFlipType' does not exist in the current context c:\users\martyn ball\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs 21 32 ConsoleApplication1
[/code]


Answers (1)