Re: Resize and crop uploaded pics

  •  10-08-2009, 5:33 AM

    Re: Resize and crop uploaded pics

    Rich,
     
    You can crop the image by drawing it to another image object :
     
    Image newimg=new System.Drawing.Bitmap(width,height,System.Drawing.Imaging.PixelFormat.Format24bppRgb);
    using(System.Drawing.Graphics g=System.Drawing.Graphics.FromImage(newimg))
    {
        g.InterpolationMode=System.Drawing.Drawing2D.InterpolationMode.High;
        g.DrawImage(srcimg
         , new System.Drawing.Rectangle(x,y,w,h)
         , new System.Drawing.Rectangle(0, 0, srcimg.Width, srcimg.Height)
         , System.Drawing.GraphicsUnit.Pixel);
    }
    newimg.Save(...)
    When you have different width/height,x,y,w,h specified , you will get different result.
    Calculate it to the value as you want.
     
    Regards,
    Terry
View Complete Thread