Crop Bitmap - CSharp System.Drawing

CSharp examples for System.Drawing:Image Operation

Description

Crop Bitmap

Demo Code


using System.Windows.Media.Imaging;
using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.IO;/*from  w w w .ja va 2  s .  c o m*/
using System.Drawing.Imaging;
using System.Drawing;
using System.Collections.Generic;
using System;

public class Main{
        public static 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;
        }
}

Related Tutorials