How can I resize an image on server that I just uploaded? I using C# with .NET Framework 3.5 SP1.
Thanks!
How can I resize an image on server that I just uploaded? I using C# with .NET Framework 3.5 SP1.
Thanks!
Have you tried this?
public Image resize( Image img, int width, int height )
{
Bitmap b = new Bitmap( width, height ) ;
Graphics g = Graphics.FromImage( (Image ) b ) ;
g.DrawImage( img, 0, 0, width, height ) ;
g.Dispose() ;
return (Image ) b ;
}
the snippet I always use:
var target = new Bitmap(size.Width, size.Height, PixelFormat.Format24bppRgb);
target.SetResolution(source.HorizontalResolution,
source.VerticalResolution);
using (var graphics = Graphics.FromImage(target))
{
graphics.Clear(Color.White);
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.DrawImage(source,
new Rectangle(destX, destY, destWidth, destHeight),
new Rectangle(sourceX, sourceY, source.Width, source.Height),
GraphicsUnit.Pixel);
}
return target;
Try the following method: