пятница, 9 июля 2010 г.

dot.Net c# - Подрезка и изменение размера изображения.

System.Drawing.Image image = System.Drawing.Image.FromFile(src);  
int srcWidth=image.Width;
int srcHeight=image.Height; 
int thumbHeight=(srcHeight/srcWidth)*thumbWidth;
Bitmap bmp = new Bitmap(thumbWidth, thumbHeight);  

System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmp); 
gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality  ; 
gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; 
gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; 

System.Drawing.Rectangle rectDestination = new System.Drawing.Rectangle(0, 0, thumbWidth, thumbHeight);
gr.DrawImage(image, rectDestination, 0, 0, srcWidth, srcHeight, GraphicsUnit.Pixel);  

bmp.Save(dest); 
  
bmp.Dispose();
image.Dispose();

Комментариев нет: