A possible solution may be as follows:
int imageFilelength = FileUpload1.PostedFile.ContentLength; byte[] ph = new byte[imageFilelength]; MemoryStream ms = new MemoryStream(ph); Image img = System.Drawing.Image.FromStream(ms);
private Image RezizeImage(Image img, int maxWidth, int maxHeight) { if(img.Height < maxHeight && img.Width < maxWidth) return img; using (img) { Double xRatio = (double)img.Width / maxWidth; Double yRatio = (double)img.Height / maxHeight; Double ratio = Math.Max(xRatio, yRatio); int nnx = (int)Math.Floor(img.Width / ratio); int nny = (int)Math.Floor(img.Height / ratio); Bitmap cpy = new Bitmap(nnx, nny, PixelFormat.Format32bppArgb); using (Graphics gr = Graphics.FromImage(cpy)) { gr.Clear(Color.Transparent);
source share