Image主要实现读取图片文件(Image.FromFile)和保存图像文件(Image.Save)。
只要将图片转为Image类之后,就可以用.Net里面强大的GDI+功能
GDI+必须先要创建Graphics,一般的创建方法有Panel1.CreateGraphics
Graphics的DrawLine,DrawString,DrawImage都是十分常用的方法。
例如:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1
Dim
oImg
As
Image
=
Image.FromFile(a.FileName)
2
3 Dim x As Integer = oImg.Width / 4
4 Dim y As Integer = oImg.Height / 4
5 Dim w As Integer = oImg.Width / 2
6 Dim h As Integer = oImg.Height / 2
7 Dim oSaveImg As Image = New Bitmap(w, h)
8
9 Dim g As Graphics = Graphics.FromImage(oSaveImg)
10
11 g.DrawImage(oImg, 0 , 0 , New Rectangle(x, y, w, h), GraphicsUnit.Pixel)
12 g.Dispose()
13
14 oSaveImg.Save( " D:\Test.jpg " , Imaging.ImageFormat.Jpeg)
15
16 Me .PictureBox1.Image = oSaveImg
2
3 Dim x As Integer = oImg.Width / 4
4 Dim y As Integer = oImg.Height / 4
5 Dim w As Integer = oImg.Width / 2
6 Dim h As Integer = oImg.Height / 2
7 Dim oSaveImg As Image = New Bitmap(w, h)
8
9 Dim g As Graphics = Graphics.FromImage(oSaveImg)
10
11 g.DrawImage(oImg, 0 , 0 , New Rectangle(x, y, w, h), GraphicsUnit.Pixel)
12 g.Dispose()
13
14 oSaveImg.Save( " D:\Test.jpg " , Imaging.ImageFormat.Jpeg)
15
16 Me .PictureBox1.Image = oSaveImg
就能实现图片的截取。