|
You can use the DrawImage method: suppose you have read your image into the bitmap MyBitmap. Copy the rectangle (x,y,width,height) to a new image with:
Dim BitmapToUse As New Bitmap(Width, Height )
Dim img As Image = Image.FromHbitmap(BitmapToUse.GetHbitmap)
Dim g As Graphics = Graphics.FromImage(img)
Dim SrcRectangle As Rectangle = New Rectangle(x, y, Width, Height) Dim TargetRectangle As Rectangle = New Rectangle(0, 0, Width, Height)
g.DrawImage(MyBitmap, TargetRectangle, SrcRectangle, GraphicsUnit.Pixel)
Now img contains only the desired rectangle
You can even use this technique to enlarge of shrink the original image: just adjust the size of the Rectangle.
|