private unsafe void MainMethod()
{
FlipImgHorizontal(@"Z:\IMG\girl.jpg", "image/jpeg");
}
private void FlipImgHorizontal(string fileName, string mimeType)
{
ImageCodecInfo imgCodec;
ImgEncoder enc;
string bakupFile = fileName + ".bak";
File.Copy(fileName, bakupFile, true);
imgCodec = ImageCodecInfo.GetImageEncoders().FirstOrDefault(e => e.MimeType == mimeType);
if (imgCodec == null)
throw new ArgumentException("Invalid MimeType specified.");
enc = ImgEncoder.Transformation;
using (Bitmap bmp = new Bitmap(bakupFile))
{
using (EncoderParameters encParams = new EncoderParameters(1))
{
using (EncoderParameter encParam = new EncoderParameter(enc, (long)EncoderValue.TransformFlipHorizontal))
{
encParams.Param[0] = encParam;
bmp.Save(fileName, imgCodec, encParams);
}
}
}
}