Resize and crop uploaded pics

Last post 10-08-2009, 5:33 AM by cutechat. 1 replies.
Sort Posts: Previous Next
  •  10-06-2009, 2:31 PM 56141

    Resize and crop uploaded pics

    Hi,
     
    I don't suppose anyone has managed to resize and crop images with the Ajax Uploader have they?
     
    I can resize them easy enough, but I'm struggling with the cropping.  Basically I want my images to be 335x360 pixels.
     
    Many thanks in advance if anyone can help.
     
    Kind regards,
     
    Rich
  •  10-08-2009, 5:33 AM 56216 in reply to 56141

    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 as RSS news feed in XML