C# ile Resim (System.Drawing.Image) Boyutlandırmak

Size, ve Image parametreleri alan bir resim boyutlandırma metodu.

 
Size boyut = new Size(100, 100);
 
private static System.Drawing.Image 
                       ResimBoyutlandir(System.Drawing.Image img, Size boyut)
{
    int kaynakEn = img.Width;
    int KaynakBoy = img.Height;
    float nPercent = 0;
    float nPercentW = 0;
    float nPercentH = 0;
 
    nPercentW = ((float)boyut.Width / (float)kaynakEn);
    nPercentH = ((float)boyut.Height / (float)KaynakBoy);
 
    if (nPercentH < nPercentW)
    {
        nPercent = nPercentH;
    }
    else
    {
        nPercent = nPercentW;
    }
 
    int HedefEn = (int)(kaynakEn * nPercent);
    int HedefBoy = (int)(KaynakBoy * nPercent);
 
    Bitmap b = new Bitmap(HedefEn, HedefBoy);
    Graphics g = Graphics.FromImage((System.Drawing.Image)b);
    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
    g.DrawImage(img, 0, 0, HedefEn, HedefBoy);
    g.Dispose();
 
    return (System.Drawing.Image)b;
}
  • Facebook
  • Twitter
  • StumbleUpon
  • del.icio.us
  • Digg

Category: Csharp - C# - Comment »


Leave a Reply



Back to top