Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Community Wiki

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.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

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

Navigation

Google Ads

ASP.NET: How to crop an Image

From Wiki

Jump to: navigation, search


Summary: An example function to crop an existing image based on parameterised points

  1. Private Function CropImage(ByVal OriginalImage As Bitmap, ByVal TopLeft As Point, ByVal BottomRight As Point) As Bitmap
  2.     Dim btmCropped As New Bitmap((BottomRight.Y - TopLeft.Y), (BottomRight.X - TopLeft.X))
  3.     Dim grpOriginal As Graphics = Graphics.FromImage(btmCropped)
  4.  
  5.     grpOriginal.DrawImage(OriginalImage, New Rectangle(0, 0, btmCropped.Width, btmCropped.Height), _
  6.         TopLeft.X, TopLeft.Y, btmCropped.Width, btmCropped.Height, GraphicsUnit.Pixel)
  7.     grpOriginal.Dispose()
  8.  
  9.     Return btmCropped
  10. End Function

Example usage

  1. Dim bmpImage As New Bitmap("c:\point.jpg")
  2. bmpImage = CropImage(bmpImage, New Point(0, 0), New Point(100, 100))


This Hack is part of the ASP.NET Hacks collection

456 Rating: 2.9/5 (14 votes cast)