/// <summary> /// 이미지 사각형을 그림니다 /// </summary> /// <param name="imageSource">이미지입니다.</param> /// <param name="rect">사각형입니다.</param> /// <param name="angle">사각형의 Angle 값입니다</param> /// <returns>이미지에 Angle 이 적용된 사각형이 그려져 반환됩니다</returns> public static ImageSource ConvertVisionImageInfoToScanImageSource(ImageSource imageSource, Rect rect, double angle) { System.Windows.Media.Imaging.BitmapSource bImage = imageSource as System.Windows.Media.Imaging.BitmapSource;
DrawingVisual dVisual = new DrawingVisual(); using (DrawingContext dc = dVisual.RenderOpen()) { dc.DrawImage(bImage, new Rect(0, 0, bImage.PixelWidth, bImage.PixelHeight));
// 원본이미지 중심 기준으로 Angle 을 돌립니다. dc.PushTransform(new RotateTransform(angle, bImage.PixelWidth / 2, bImage.PixelHeight / 2)); dc.DrawRectangle((SolidColorBrush)(new BrushConverter().ConvertFrom(Colors.Blue)), null, rect); }
System.Windows.Media.Imaging.RenderTargetBitmap targetBitmap = new System.Windows.Media.Imaging.RenderTargetBitmap(bImage.PixelWidth, bImage.PixelHeight, bImage.DpiX, bImage.DpiY, PixelFormats.Default); targetBitmap.Render(dVisual);
System.Windows.Media.Imaging.WriteableBitmap wBitmap = new System.Windows.Media.Imaging.WriteableBitmap(targetBitmap);
return wBitmap; } |
'C# > WPF' 카테고리의 다른 글
[WPF] IRegionMemberLifetime (0) | 2021.07.07 |
---|---|
[WPF/Prism] Prism 참고 소스 (0) | 2021.07.04 |
[WPF] wpf 분석 필요한 소스 (Vintasoft.Imaging.Wpf.WpfObjectConverter) (0) | 2021.05.13 |
[WFP] Convert GraphicsPath To PathGeometry (0) | 2021.05.13 |
[WPF] Convert hex color value to SolidColorBrush (0) | 2021.04.05 |