| Server IP : 199.79.62.161 / Your IP : 216.73.216.245 [ Web Server : Microsoft-IIS/10.0 System : Windows NT MDUS-PP-WB12 10.0 build 20348 (Windows Server 2022) AMD64 User : IWPD_5096(nirmaowd) ( 0) PHP Version : 8.3.30 Disable Function : NONE Domains : 0 Domains MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : D:/INETPUB/VHOSTS/nirmalamatha.edu.in/ponnuguruvayurappan.org/App_Code/ |
Upload File : |
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
public class ImageResize
{
public System.Drawing.Image ScaleByPercent(System.Drawing.Image imgPhoto, float Percent, int targetCanvasWidth, int targetCanvasHeight)
{
float nPercent = (((float)(Percent)) / 100);
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destWidth = ((int)((sourceWidth * nPercent)));
int destHeight = ((int)((sourceHeight * nPercent)));
int destX = (targetCanvasWidth - destWidth) / 2;
int destY = (targetCanvasHeight - destHeight) / 2;
Bitmap bmPhoto = new Bitmap(targetCanvasWidth, targetCanvasHeight, PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;
grPhoto.Clear(System.Drawing.Color.FromArgb(34, 54, 70));
grPhoto.DrawImage(imgPhoto, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel);
grPhoto.Dispose();
return bmPhoto;
}
public System.Drawing.Image CreateThumbNail(Bitmap postedFile, int width, int height)
{
System.Drawing.Image imgBanner;
ImageFormat Format = postedFile.RawFormat;
Decimal Ratio;
int NewWidth;
int NewHeight;
// *** If the image is smaller than a thumbnail just return it
if ((postedFile.Width > postedFile.Height))
{
Ratio = Convert.ToDecimal((Convert.ToDecimal(width) / postedFile.Width));
NewWidth = width;
Decimal Temp = (postedFile.Height * Ratio);
NewHeight = Convert.ToInt32(Temp);
}
else
{
Ratio = Convert.ToDecimal((Convert.ToDecimal(height) / postedFile.Height));
NewHeight = height;
Decimal Temp = (postedFile.Width * Ratio);
NewWidth = Convert.ToInt32(Temp);
}
float per = (float)(Ratio * 100);
imgBanner = NewScaleByPercent(postedFile, per, width, height);
return imgBanner;
}
public static System.Drawing.Image NewScaleByPercent(System.Drawing.Image imgPhoto, float Percent, int targetCanvasWidth, int targetCanvasHeight)
{
float nPercent = ((float)Percent / 100);
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0;
int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);
int destX = (targetCanvasWidth - destWidth) / 2;
int destY = (targetCanvasHeight - destHeight) / 2;
Bitmap bmPhoto = new Bitmap(targetCanvasWidth, targetCanvasHeight, PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;
grPhoto.Clear(Color.White);
grPhoto.DrawImage(imgPhoto,
new Rectangle(destX, destY, destWidth, destHeight),
new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
GraphicsUnit.Pixel);
grPhoto.Dispose();
return bmPhoto;
}
}