728x90
728x170

/// <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;

}

 

728x90
그리드형
Posted by kjun.kr
,