c#图片的剪裁方法

//oldUrl图片所在文件夹的路径

//newUrl新图片存储路径

void toCut(string oldUrl,string newUrl)
        {
            BitmapImage myBitmapImage1 = new BitmapImage();
            myBitmapImage1.BeginInit();
            myBitmapImage1.UriSource = new Uri(oldUrl, UriKind.Absolute);
            myBitmapImage1.EndInit();
            CroppedBitmap cb = new CroppedBitmap(myBitmapImage1, new Int32Rect(173, 83, 292, 292));
            FileStream stream = new FileStream(newUrl, FileMode.OpenOrCreate);
            PngBitmapEncoder encoder = new PngBitmapEncoder();
            encoder.Interlace = PngInterlaceOption.On;
            encoder.Frames.Add(BitmapFrame.Create(cb));
            encoder.Save(stream);
            stream.Close();
        }

 

你可能感兴趣的:(c#图片的剪裁方法)