private void Cvs_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { if (e.LeftButton == MouseButtonState.Released) { if (IsCropMode) { CropEnd = e.GetPosition(Cvs); if (CropEnd.X > ImageEndPoint.X) { CropEnd.X = ImageEndPoint.X; } if (CropEnd.X < ImageStartPoint.X) { CropEnd.X = ImageStartPoint.X; } if (CropEnd.Y > ImageEndPoint.Y) { CropEnd.Y = ImageEndPoint.Y; } if (CropEnd.Y < ImageStartPoint.Y) { CropEnd.Y = ImageStartPoint.Y; } IsCropMode = false; Cvs.Children.Remove(image); Cvs.Children.Remove(path); //切割圖片 ImageSource imageSource = image.Source; System.Drawing.Bitmap bitmap = ImageProcess.ImageSourceToBitmap(imageSource); BitmapSource bitmapSource = ImageProcess.BitmapToBitmapImage(bitmap); double ratio = heightRatio > 0 ? heightRatio : widthRatio; BitmapSource newBitmapSource = ImageProcess.CutImage(bitmapSource, new Int32Rect((int)((rect2.Left - ImageStartPoint.X) / ratio), (int)((rect2.Top - ImageStartPoint.Y) / ratio), (int)(cropWidth / ratio), (int)(cropHeight / ratio))); SettingImage(newBitmapSource); //執行過編輯 可以復原 buttonUndo.IsEnabled = true; //執行過編輯 可以儲存 buttonSure.IsEnabled = true; } } }