diff --git a/MarketData/MarketDataLib/CNNProcessing/ImageHelper.cs b/MarketData/MarketDataLib/CNNProcessing/ImageHelper.cs index dd6e549..0bedaf1 100644 --- a/MarketData/MarketDataLib/CNNProcessing/ImageHelper.cs +++ b/MarketData/MarketDataLib/CNNProcessing/ImageHelper.cs @@ -507,14 +507,14 @@ namespace MarketData.CNNProcessing canvas.DrawLine(txSrcPoint, txDstPoint, paint); } - /// - /// Draw text on the bitmap - /// - /// - /// - /// - /// - public void DrawText(String text, SKPoint srcPoint, SKColor color, SKTextAlign align, SKFont font,SKPaintStyle paintStyle=SKPaintStyle.Fill,float strokeWidth = 1) + /// + /// Draw text on the bitmap + /// + /// + /// + /// + /// + public void DrawText(String text, SKPoint srcPoint, SKColor color, SKTextAlign align, SKFont font,SKPaintStyle paintStyle=SKPaintStyle.Fill,float strokeWidth = 1) { Validate(); SKPoint txSrcPoint = pointMapping.MapPoint(srcPoint); @@ -524,36 +524,52 @@ namespace MarketData.CNNProcessing paint.StrokeWidth = strokeWidth; // Set the desired stroke width paint.Color = color; canvas.DrawText(text,srcPoint, align, font, paint); + } + + /// + /// Create a rectangle with the specified text + /// + /// + /// + /// + /// + /// + /// + /// + public void CreateBoundedText(String text, SKColor textColor, SKColor fillColor, SKTextAlign align, SKFont font, SKPaintStyle paintStyle = SKPaintStyle.Fill, float strokeWidth = 1) + { + SKPoint srcPoint = new SKPoint(2, (int)font.Size + 4); + int width = GetTextLength(text, font) + 4; + int height = (int)font.Size * 2; + CreateImage(width, height); + Fill(fillColor); + DrawLine(SKColors.Black, 1, new SKPoint(0, 0), new SKPoint(width - 1, 0)); // bottom left to right + DrawLine(SKColors.Black, 1, new SKPoint(width - 1, 0), new SKPoint(width - 1, height - 1)); // up lefthand side + DrawLine(SKColors.Black, 1, new SKPoint(0, height - 1), new SKPoint(width - 1, height - 1)); // top left to right + DrawLine(SKColors.Black, 1, new SKPoint(0, height - 1), new SKPoint(0, 0)); // left hand side top to bottom + DrawText(text, srcPoint, textColor, align, font); } - public void DrawBoundedText(String text, SKPoint srcPoint, SKColor color, SKTextAlign align, SKFont font,SKPaintStyle paintStyle=SKPaintStyle.Fill,float strokeWidth = 1) + /// + /// Gets the length of the text + /// + /// + /// + /// + /// + /// + public int GetTextLength(String text, SKFont font, SKPaintStyle paintStyle = SKPaintStyle.Fill, float strokeWidth = 1) { -// Validate(); -// SKPoint txSrcPoint = pointMapping.MapPoint(srcPoint); - using SKPaint paint = new SKPaint(); paint.Style = paintStyle; paint.StrokeWidth = strokeWidth; // Set the desired stroke width - paint.Color = color; + paint.Color = SKColors.Transparent; SKRect rect = new SKRect(0, 0, 0, 0); - float textSize = font.MeasureText(text,out rect,paint); - CreateImage((int)rect.Width+1,(int)rect.Height+1); - SKPoint txSrcPoint = pointMapping.MapPoint(srcPoint); - using SKCanvas canvas = new SKCanvas(bitmap); - - - canvas.DrawText(text,srcPoint, align, font, paint); - } - - // float textSize = fonts[0].MeasureText(displayText,out rect,SKPaint); - // imageHelper.CreateImage(width, height); - // imageHelper.Fill(SKColors.White); - // imageHelper.DrawLine(SKColors.Black, 1, new SKPoint(0, 0), new SKPoint(width - 1, 0)); // bottom left to right - // imageHelper.DrawLine(SKColors.Black, 1, new SKPoint(width - 1, 0), new SKPoint(width - 1, height - 1)); // up lefthand side - // imageHelper.DrawLine(SKColors.Black, 1, new SKPoint(0, height - 1), new SKPoint(width - 1, height - 1)); // top left to right - // imageHelper.DrawLine(SKColors.Black, 1, new SKPoint(0, height - 1), new SKPoint(0, 0)); // left hand side top to bottom - // imageHelper.DrawText(displayText, new SKPoint(2, 16), SKColors.White, align, fonts[index]); + float textLength = font.MeasureText(text, out rect, paint); + return (int)textLength; + } + /// /// Draws the path along the line segments /// @@ -569,11 +585,11 @@ namespace MarketData.CNNProcessing paint.Style = SKPaintStyle.Stroke; paint.StrokeWidth = strokeWidth; // Set the desired stroke width paint.Color = SKColors.Black; - foreach(LineSegment lineSegment in lineSegments) + foreach (LineSegment lineSegment in lineSegments) { - SKPoint txSrcPoint=pointMapping.MapPoint(lineSegment.P1); - SKPoint txDstPoint=pointMapping.MapPoint(lineSegment.P2); - canvas.DrawLine(txSrcPoint, txDstPoint, paint); + SKPoint txSrcPoint = pointMapping.MapPoint(lineSegment.P1); + SKPoint txDstPoint = pointMapping.MapPoint(lineSegment.P2); + canvas.DrawLine(txSrcPoint, txDstPoint, paint); } }