Asp.net resim boyutlandırma kodu

25. Haziran 2009

      Benin kullandığım 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();

                }

10 kişi tarafından 3.8 olarak değerlendirildi

  • Currently 3,8/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Asp.net

Yorumlar

Yorum ekle


(Gravatar simgesini gösterecek)  

  Country flag

biuquote
  • Yorum
  • Canlı önizleme
Loading