一个裁剪图片的过程

呵。。一个裁剪图片的过程,
 1 private bool CreteCropImage(string oldFilePath,string CropFilePath,int x,int y,int w,int h,int scale)
 2        {
 3            System.Drawing.Image sImage;
 4            sImage = System.Drawing.Image.FromFile(oldImageFilePath);
 5            Bitmap bitmap = new Bitmap(w, h, PixelFormat.Format32bppArgb);
 6            Graphics g = Graphics.FromImage(bitmap);
 7            Rectangle destRect=new Rectangle(00,w,h);
 8            int newx=x*100/scale;
 9            int newy=y*100/scale;
10            int neww=w*100/scale;
11            int newh=h*100/scale;
12            g.DrawImage(sImage,destRect,newx,newy ,neww ,newh,GraphicsUnit.Pixel);
13            MemoryStream ms=new MemoryStream();                
14            bitmap.Save(ms, ImageFormat.Jpeg); 
15            ms.GetBuffer();
16            FileStream f;
17            try
18            {
19                f = new FileStream(CropImagePath, FileMode.Create,FileAccess.ReadWrite,FileShare.Write);    
20            }

21            catch
22            {
23                throw;
24            }

25            ms.WriteTo(f);
26            ms.Close();
27            f.Close();
28            f = null;
29            ms = null;
30            g.Dispose();
31            bitmap.Dispose();
32            sImage.Dispose();
33            return true;
34        }
posted on 2005-10-23 17:41  轻舞flash  阅读(975)  评论(0编辑  收藏  举报