Geçen gün bir arkadaşımın şiddetli sitemiyle blog’u boşlama işine bir son vermiş durumdayım.  Söz konusu sitemin sebebi siteye imaj yükleme işlemi sırasında imajı bozmadan yeniden boyutlandırma ile ilgili bir kod bloğu.  Kendisinin de inceleyip onayladığı bu kodları blogumda yayınlamak bir yana uzun süredir yazmadığımı yüzüme vurunca utandım haliyle J  İşte söz konusu imaj boyutlandırma bloğu:

public System.Drawing.Bitmap CreateThumbnail(System.IO.Stream lcStream, int lnWidth, int lnHeight)
{
   
System.Drawing.
Bitmap bmpOut = null;
   
try
   
{
      
System.Drawing.
Bitmap loBMP = new System.Drawing.Bitmap(lcStream);
      
System.Drawing.Imaging.
ImageFormat loFormat = loBMP.RawFormat;

      decimal lnRatio;
      
int lnNewWidth = 0;
      
int lnNewHeight = 0;

      if (loBMP.Width < lnWidth && loBMP.Height < lnHeight)
         
return loBMP;

      if (loBMP.Width > loBMP.Height)
      
{
         
lnRatio = (
decimal)lnWidth / loBMP.Width;
         
lnNewWidth = lnWidth;

         decimal lnTemp = loBMP.Height * lnRatio;
         
lnNewHeight = (
int)lnTemp;
      
}
      
else
      
{

         lnRatio = ( decimal)lnHeight / loBMP.Height;
         
lnNewHeight = lnHeight;>

         decimal lnTemp = loBMP.Width * lnRatio;
         
lnNewWidth = (
int)lnTemp;
      
}

      
bmpOut =
new System.Drawing.Bitmap(lnNewWidth, lnNewHeight);
      
System.Drawing.
Graphics g = Graphics.FromImage(bmpOut);
      
g.InterpolationMode = System.Drawing.Drawing2D.
InterpolationMode.HighQualityBicubic;
      
g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight);
      
g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight);>

      loBMP.Dispose();
   
}
   
catch
   
{
      
return null;
   
}
   

   return bmpOut;

}