ASP.NET: How to crop an Image
From Wiki
Summary: An example function to crop an existing image based on parameterised points
- Private Function CropImage(ByVal OriginalImage As Bitmap, ByVal TopLeft As Point, ByVal BottomRight As Point) As Bitmap
- Dim btmCropped As New Bitmap((BottomRight.Y - TopLeft.Y), (BottomRight.X - TopLeft.X))
- Dim grpOriginal As Graphics = Graphics.FromImage(btmCropped)
- grpOriginal.DrawImage(OriginalImage, New Rectangle(0, 0, btmCropped.Width, btmCropped.Height), _
- TopLeft.X, TopLeft.Y, btmCropped.Width, btmCropped.Height, GraphicsUnit.Pixel)
- grpOriginal.Dispose()
- Return btmCropped
- End Function
Example usage
- Dim bmpImage As New Bitmap("c:\point.jpg")
- bmpImage = CropImage(bmpImage, New Point(0, 0), New Point(100, 100))
This Hack is part of the ASP.NET Hacks collection


