I have got:
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
public byte[] CropImage(Image OriginalImage, int Width, int Height, int X, int Y)
{
try
{
Bitmap bmp = new Bitmap(Width, Height);
bmp.SetResolution(OriginalImage.HorizontalResolution, OriginalImage.VerticalResolution);
Graphics Graphic = Graphics.FromImage(bmp);
Graphic.SmoothingMode =SmoothingMode.AntiAlias;
Graphic.InterpolationMode =InterpolationMode.HighQualityBicubic;
Graphic.PixelOffsetMode =PixelOffsetMode.HighQuality;
Graphic.DrawImage(OriginalImage,new Rectangle(0, 0, Width, Height), X, Y, Width, Height, GraphicsUnit.Pixel);
MemoryStream ms = newMemoryStream();
bmp.Save(ms, OriginalImage.RawFormat);
return ms.GetBuffer();
}
catch (Exception Ex)
{
throw (Ex);
}
}
You can use as:
byte[] CroppedImage = null;
CroppedImage = CropImage(OriginalImage, imageWidth, imageHeight, x, y);
Where imageWidth=width of required image
imageHeight=hight of required image
x=x-coordinate
y=ycoordinate