View Single Post
  #51 (permalink)  
Old 09-06-2007, 11:27 PM
tiermann's Avatar
tiermann
VIP Member
Offline
Threadstarter
Location: PA, USA
 
Join Date: Apr 2007
Posts: 815
Reputation: 3165
tiermann is still contributing even after becoming a VIPtiermann is still contributing even after becoming a VIPtiermann is still contributing even after becoming a VIPtiermann is still contributing even after becoming a VIPtiermann is still contributing even after becoming a VIPtiermann is still contributing even after becoming a VIPtiermann is still contributing even after becoming a VIPtiermann is still contributing even after becoming a VIPtiermann is still contributing even after becoming a VIPtiermann is still contributing even after becoming a VIPtiermann is still contributing even after becoming a VIP
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Send a message via AIM to tiermann Send a message via Yahoo to tiermann
Code:
Public Function CaptureRectangle(ByVal bmp As Bitmap, ByVal CapRect As Rectangle, ByVal CapRectWidth As Integer, ByVal CapRectHeight As Integer) As Bitmap
        Dim bmpImage As Bitmap = bmp
        Dim bmpCrop As New Bitmap(CapRectWidth, CapRectHeight)
        Dim recCrop As New Rectangle(CapRect.X, CapRect.Y, CapRectWidth, CapRectHeight)
        Dim gphCrop As Graphics = Graphics.FromImage(bmpCrop)
        Dim recDest As New Rectangle(0, 0, CapRectWidth, CapRectHeight)
        Dim attr As New System.Drawing.Imaging.ImageAttributes
        gphCrop.DrawImage(bmpImage, recDest, recCrop.X, recCrop.Y, recCrop.Width, recCrop.Height, GraphicsUnit.Pixel, attr)

        gphCrop.Dispose()
        Return bmpCrop

    End Function
That will return a bitmap cropped out of the original image at the start position and width/height specified. Usage is like...

'Define these to the section you want to crop out of the picture
Dim startX, startY, cWidth, cHeight as Integer

Dim oldbmp as Bitmap = new Bitmap("C:\MyPicture.jpg")
Dim newbmp as Bitmap = captureRectangle(oldbmp, new Rectangle(startX,StartY,cWidth,cHeight), cWidth, cHeight)
Reply With Quote