Beispiel #1
0
        public static void Rotate90(string fileName)
        {
            Image  Pic;
            string FileNameTemp;

            System.Drawing.Imaging.Encoder Enc = System.Drawing.Imaging.Encoder.Transformation;
            EncoderParameters EncParms         = new EncoderParameters(1);
            EncoderParameter  EncParm;
            ImageCodecInfo    CodecInfo = GetEncoderInfo("image/jpeg");

            // load the image to change
            Pic = Image.FromFile(fileName);

            Image Pic2 = (Image)Pic.Clone();

            // we cannot store in the same image, so use a temporary image instead
            FileNameTemp = fileName + ".temp";

            // for rewriting without recompression we must rotate the image 90 degrees
            EncParm           = new EncoderParameter(Enc, (long)EncoderValue.TransformRotate90);
            EncParms.Param[0] = EncParm;

            // now write the rotated image with new description
            Pic.Save(FileNameTemp, CodecInfo, EncParms);
            Pic.Dispose();
            Pic = null;

            // delete the original file, will be replaced later
            //System.IO.File.Delete(fileName);
            //System.IO.File.Move(FileNameTemp, fileName);
        }