Last post Sep 13, 2016 01:26 AM by Deepak Panchal
Sep 12, 2016 03:17 AM|asplearning|LINK
Hello everyone, I have this problem. I would like to let my user to be able to upload image to my site however,
1. I would to crop the image into a 1280 X 1280 pixel square image if the image both width and height are bigger than 1280.
2. if either height or width is smaller than 1280 pixel, then I would like to add white background to make up for the difference and create a square image.
Is there a simple way to do this? I found this functionality:
public Image Crop(string img, int width, int height, int x, int y)
Image image = Image.FromFile(img);
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
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);
// Dispose to free up resources
catch (Exception ex)
it doesn't really crop my image when my image has height and width more than 1280.
Sep 12, 2016 05:34 AM|SURYA_TECH|LINK
You can use the plug in called as Cropper.js.
You find here :-
or Jquery has lot of plugin you can found this here :-
Sep 12, 2016 12:01 PM|asplearning|LINK
Thank you for your reply. But I am not doing any cropping on the client side. I have a file upload control and the user select an image file. When they click submit, I would like to process the image. So actually the user didn't do any cropping.
Sep 13, 2016 01:26 AM|Deepak Panchal|LINK
you had mentioned in the title of this thread that you want to Resize the image.
but in the description of thread you are talking about Cropping an image.
cropping and resizing both are different things.
so please clear you want to resize or crop?
in your last post you had mentioned that your code not cropping an image.
so here I assume that you want to crop the image.
please try to refer the code mentioned below.
Image image = new Bitmap("Apple.gif");
// Draw the image unaltered with its upper-left corner at (0, 0).
e.Graphics.DrawImage(image, 0, 0);
// Make the destination rectangle 30 percent wider and
// 30 percent taller than the original image.
// Put the upper-left corner of the destination
// rectangle at (150, 20).
int width = image.Width;
int height = image.Height;
RectangleF destinationRect = new RectangleF(
1.3f * width,
1.3f * height);
// Draw a portion of the image. Scale that portion of the image
// so that it fills the destination rectangle.
RectangleF sourceRect = new RectangleF(0, 0, .75f * width, .75f * height);
for more information regarding cropping an image please visit the link below.
How to: Crop and Scale Images