I am trying to build this class (for use on ASP.NET site) that will crop the image based on user width, height X, Y, then take the result image and scale it to user width, height and save to the directory on the server returns the URL- address of this image.
And I will get these parameters in a querystring like this
Default.aspx?x=100&y=300&w=800&h=500&scalew=160&scaleh=100
So this is what I got so far
public static Image CustomCrop(int width, int height, int x, int y, int scalwidth, int scalheight)
{
try
{
Image image = Image.FromFile("Images/none.jpg");
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
bmp.SetResolution(80, 60);
Graphics gfx = Graphics.FromImage(bmp);
gfx.SmoothingMode = SmoothingMode.AntiAlias;
gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
gfx.PixelOffsetMode = PixelOffsetMode.HighQuality;
gfx.DrawImage(image, new Rectangle(0, 0, width, height), x, y, width, height, GraphicsUnit.Pixel);
return bmp;
}
catch (Exception ex)
{
return null;
}
}
I will send these values to Crop Image (width, height, x, y), then scale the cropped image (scalwidth, scalheight), then save the jpg in the directory and return the url for the image location
So what is the best way to do this?