-- AspNet MVC/Core

Aspnet Resim Boyutlandırma Kodu

public System.Drawing.Image ResimBoyutlandir(System.Drawing.Image imgPhoto, int Yukseklik)
{
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;

int destWidth = Yukseklik;
int destHeight = 200;

Bitmap bmPhoto = new Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);

Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic; 
grPhoto.FillRectangle(Brushes.White, 0, 0, destWidth, destHeight);

grPhoto.DrawImage(imgPhoto, new Rectangle(0, 0, destWidth, destHeight), new Rectangle(0, 0, sourceWidth, sourceHeight), GraphicsUnit.Pixel);

grPhoto.Dispose();
return bmPhoto;
}

 

Kullanışı

if (FileUpload1.HasFile == true)
{
string imageName = FileUpload1.FileName;
if (imageName != null)
{

System.Drawing.Image imgPhotoVert = System.Drawing.Image.FromFile(Server.MapPath(Klasor));
System.Drawing.Image imgPhoto = null;
Images img = new Images();
imgPhoto = img.ResimBoyutlandir(imgPhotoVert, yeniW); //ScaleByPercent adlı mekanızmaya yolluyoruz aldığımız bilgileri.
imgPhoto.Save(Server.MapPath("~/upload/" + gelenResim), ImageFormat.Jpeg); // Ekrana basıyoruz..
imgPhoto.Dispose();

}

 

Teşekkürler, iyi çalışmalar..

Yorumla

Yorum