Crop An Image (Bitmap) in C# or VB.NET
I looked all over the net for some sort of function and what I ended up with seemed rather simple function to crop an bitmap.
Here is the function in C#
public Bitmap CropBitmap(Bitmap bitmap, int cropX, int cropY, int cropWidth, int cropHeight)
{
Rectangle rect = new Rectangle(cropX, cropY, cropWidth, cropHeight);
Bitmap cropped = bitmap.Clone(rect, bitmap.PixelFormat);
return cropped;
}
And the same 3-liner in VB.NET
Private Function CropBitmap(ByRef bmp As Bitmap, ByVal cropX As Integer, ByVal cropY As Integer, ByVal cropWidth As Integer, ByVal cropHeight As Integer) As Bitmap
Dim rect As New Rectangle(cropX, cropY, cropWidth, cropHeight)
Dim cropped As Bitmap = bmp.Clone(rect, bmp.PixelFormat)
Return cropped
End Function
(Sorry the format is not that great on my blog here.)
[tags]vb.net, c#, crop, image, bitmap, visual studio[/tags]
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.
February 12, 2007
·
Dustin ·
18 Comments
Posted in: Programming & Internet
-
Jason L
-
Sudipta Mukherjee
-
http://www.reelix.za.net/ Reelix
-
farz
-
http://www.reelix.za.net/ Reelix
-
Anonymous
-
http://www.michaelellerbeck.com Michael
-
Te3ahight
-
Ell
-
http://www.vbknowledgebase.com Pon
-
David Andersson
-
Hscoder
-
George
-
Billy
-
Svmbabu547
-
Andy
-
http://imageresizing.net/ Nathanael Jones
-
Sue


