1 using System;
2 using System.Collections.Generic;
3 using System.Drawing;
4 using System.Drawing.Imaging;
5 using System.Text;
6
7 namespace SuperDLL
8 {
9 /// <summary>
10 /// 图片操作
11 /// </summary>
12 public static class D002_Picture
13 {
14 /// <summary>
15 /// 裁剪
16 /// </summary>
17 /// <param name="fromImagePath"></param>
18 /// <param name="offsetX"></param>
19 /// <param name="offsetY"></param>
20 /// <param name="width"></param>
21 /// <param name="height"></param>
22 /// <param name="toImagePath"></param>
23 public static void CaptureImage(string fromImagePath, int offsetX, int offsetY, int width, int height, string toImagePath)
24 {
25 Image fromImage = Image.FromFile(fromImagePath);
26 Bitmap bitmap = new Bitmap(width, height);
27 Graphics graphics = Graphics.FromImage(bitmap);
28 graphics.DrawImage(fromImage, 0, 0, new Rectangle(offsetX, offsetY, width, height), GraphicsUnit.Pixel);
29 Image saveImage = Image.FromHbitmap(bitmap.GetHbitmap());
30 saveImage.Save(toImagePath, ImageFormat.Png);
31 fromImage.Dispose();
32 bitmap.Dispose();
33 graphics.Dispose();
34 saveImage.Dispose();
35 }
36 }
37 }