Dev::DotNet/WPF
BitmapSource 이미지 일부 잘라내기
isfry
2018. 10. 26. 15:55
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | public BitmapSource CropImage(BitmapSource aImage, Rect aCropRect) { if (aImage == null) throw new ArgumentNullException("Image"); var rect = new Rect(0, 0, aImage.PixelWidth, aImage.PixelHeight); if (!rect.IntersectsWith(aCropRect)) throw new ArgumentOutOfRangeException("Crop Rect"); rect.Intersect(aCropRect); return new CroppedBitmap( aImage, new Int32Rect( (int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height)); } | cs |