using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
namespace WebApplication1
{
public partial class About : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int x, y, width, height;
x = y = 0; //X, Y values for crop the image.
width = 300;
height = 300;
Rectangle cropArea = new Rectangle(x, y, width, height);
Bitmap bmpImage = new Bitmap(FileUpload1.PostedFile.InputStream);
Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat);
bmpCrop.Save(@"D:\test.jpg");
}
}
}
Since we are using Rectangle and Bitmap classes, we have to import the System.Drawing namespace. Here I’m defining the width and height as 300px and X, Y value to 0. So it will crop 300x300 area from the image from the top left corner. Following is the markup I’ve used
Comments
Post a Comment