Rotating and Saving an image

martynball

Member
Joined
Jul 8, 2014
Messages
14
Programming Experience
Beginner
Need to benchmark some rotations! Getting errors from the below code. All I want to do is simply rotate the image in memory and save it, also calculate how long it took for testing on a slower machine.

C#:
        private void rotatec_Click(object sender, EventArgs e)
        {
            Image image1 = pictureBox1.Image;
            if (image1 != null)
            {
                string save1 = DateTime.Now.ToString("HH:mm:ss.ffffff");
                image1.RotateFlip(RotateFlipType.Rotate90FlipY);
                pictureBox1.BackgroundImage = image1;
                image1.Save(@".\test.jpg");
                string save2 = DateTime.Now.ToString("HH:mm:ss.ffffff");
                int text = Convert.ToInt32(save1) - Convert.ToInt32(save2);  //Line 35 here! 


                //Write to text file
                System.IO.StreamWriter file = new System.IO.StreamWriter(@".\numbers.txt");
                file.WriteLine(text);
                file.Close();
            }
        }

Errors:
C#:
>	JamSnaps.exe!JamSnaps.Form1.rotatec_Click(object sender, System.EventArgs e) Line 35	C#
>	JamSnaps.exe!JamSnaps.Program.Main() Line 19	C#
 
Never mind, fixed it:
C#:
private void rotatec_Click(object sender, EventArgs e)
        {
            Image image1 = pictureBox1.Image;
            if (image1 != null)
            {
                System.Diagnostics.Stopwatch s = System.Diagnostics.Stopwatch.StartNew();


                image1.RotateFlip(RotateFlipType.Rotate90FlipY);
                pictureBox1.BackgroundImage = image1;
                image1.Save(@".\test.jpg");


                s.Stop();
                string text = "Time took: {0} ms" + s.ElapsedMilliseconds + ". Microseconds: " + (s.ElapsedMilliseconds * 1000);


                //Write to text file
                System.IO.StreamWriter file = new System.IO.StreamWriter(@".\timetook.txt");
                file.WriteLine(text);
                file.Close();
            } 
            else
            {
                MessageBox.Show("Please load an image first!");
            }
        }

used System.Diagnostics.Stopwatch instead of timedate!
 
Back
Top Bottom