1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
| using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using System.Drawing; using System.IO; using System.Web; using System.Drawing.Imaging;
namespace Test1 { class Program { private static Bitmap _origImg;
static void Main(string[] args) { ImagePath(@"C:\Users\98468\Desktop\图片识别\55.png"); }
public static void ImagePath(string ImgPath) { try { _origImg = (Bitmap)Image.FromFile(ImgPath).Clone();
string name = Path.GetFileNameWithoutExtension(ImgPath); string name_path = Path.GetFileName(ImgPath); string path= Path.GetExtension(ImgPath); ImageRotate(1, name,path); } catch { }
}
public static void ImageRotate(int SelectedIndex,string name,string path) { try { Bitmap bmp; BitmapFlip(_origImg, SelectedIndex, out bmp); Image image = bmp; var A = ImageFormat.Png; SaveToFile1(image, name + path, true, A); string Text = "当前序号:" + SelectedIndex.ToString(); } catch { } }
private static void BitmapFlip(Bitmap btSource, int iFlip, out Bitmap btDes) { btDes = (Bitmap)_origImg.Clone(); switch (iFlip) { case 0: btDes.RotateFlip(RotateFlipType.Rotate180FlipNone); break; case 1: btDes.RotateFlip(RotateFlipType.Rotate270FlipXY); break; case 2: btDes.RotateFlip(RotateFlipType.Rotate180FlipNone); break; case 3: btDes.RotateFlip(RotateFlipType.Rotate270FlipNone); break; case 4: btDes.RotateFlip(RotateFlipType.Rotate180FlipY); break; case 5: btDes.RotateFlip(RotateFlipType.Rotate90FlipX); break; case 6: btDes.RotateFlip(RotateFlipType.RotateNoneFlipY); break; case 7: btDes.RotateFlip(RotateFlipType.Rotate90FlipY); break; }
}
public static void SaveToFile(Image pic, String name, ImageFormat format) { string CurDir = AppDomain.CurrentDomain.BaseDirectory + DateTime.Now.Date.ToString("yyyy_MM_dd") + @"(PngSplit)导出\"; if (!Directory.Exists(CurDir)) Directory.CreateDirectory(CurDir);
SaveToFile1(pic, CurDir + name, true, format); } public static void SaveToFile1(Image pic, string fileName, bool replace, ImageFormat format) { if(File.Exists(fileName) && replace) { File.Delete(fileName); }
if (!File.Exists(fileName)) { if (format == null) { pic.Save(fileName); } else { pic.Save(fileName); } } }
} }
|