如何在vb.net中裁剪图像?

前端之家收集整理的这篇文章主要介绍了如何在vb.net中裁剪图像?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
图像可以是任何东西.它可以是jpg,png,任何东西.

加载它.

裁剪它.假设从左侧删除前100个像素.

保存到同一个文件

使用 Graphics.DrawImage Method (Image,RectangleF,GraphicsUnit)方法.
  1. Dim fileName = "C:\file.jpg"
  2. Dim CropRect As New Rectangle(100,100,100)
  3. Dim OriginalImage = Image.FromFile(fileName)
  4. Dim CropImage = New Bitmap(CropRect.Width,CropRect.Height)
  5. Using grp = Graphics.FromImage(CropImage)
  6. grp.DrawImage(OriginalImage,New Rectangle(0,CropRect.Width,CropRect.Height),CropRect,GraphicsUnit.Pixel)
  7. OriginalImage.Dispose()
  8. CropImage.Save(fileName)
  9. End Using

猜你在找的VB相关文章