Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
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



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.