private void DrawRoiDown(ImageDrawing id) { int x1 = ptRoiStart.X; int y1 = ptRoiStart.Y; int x2 = ptRoiEnd.X; int y2 = ptRoiEnd.Y; if (x1 > x2) { Util.Swap(ref x1, ref x2); } if (y1 > y2) { Util.Swap(ref y1, ref y2); } var roi = new Rectangle(x1, y1, x2 - x1, y2 - y1); var roiF = new RectangleF(roi.X - 0.5f, roi.Y - 0.5f, roi.Width, roi.Height); string roiStart = $"({roi.Left},{roi.Top})"; string roiEnd = $"({roi.Width},{roi.Height})"; var sizeStart = id.MeasureString(roiStart, Fonts.Ascii_10x18); var zoom = GetZoomFactor(); id.DrawString(roiStart, Fonts.Ascii_10x18, Option.RoiRectangleColor, roiF.X - sizeStart.Width / (float)zoom, roiF.Y - sizeStart.Height / (float)zoom, Color.Yellow); id.DrawString(roiEnd, Fonts.Ascii_10x18, Option.RoiRectangleColor, roiF.X + roiF.Width, roiF.Y + roiF.Height, Color.Yellow); id.DrawRectangleDot(Option.RoiRectangleColor, roiF); }
private void DrawDebugInfo(ImageDrawing id) { var sb = new StringBuilder(); string imageInfo = imgBuf == IntPtr.Zero ? "X" : $"{imgBw}*{imgBh}*{imgBytepp*8}bpp{(isImgbufFloat ? "(float)" : "")}"; sb.AppendLine("== Image =="); sb.AppendLine(imageInfo); sb.AppendLine(); sb.AppendLine("== Draw =="); sb.AppendLine($"UseDrawPixelValue : {(Option.UseDrawPixelValue ? "O" : "X")}"); sb.AppendLine($"UseDrawCenterLine : {(Option.UseDrawCenterLine ? "O" : "X")}"); sb.AppendLine($"UseDrawCursorInfo : {(Option.UseDrawCursorInfo ? "O" : "X")}"); sb.AppendLine($"UseDrawDebugInfo : {(Option.UseDrawDebugInfo ? "O" : "X")}"); sb.AppendLine($"UseDrawRoiRectangles : {(Option.UseDrawRoiRectangles ? "O" : "X")}"); sb.AppendLine(); sb.AppendLine("== Time =="); if (dtListList.Count > 0) { var sumSeq = dtListList.Aggregate((dtList1, dtList2) => dtList1.Zip(dtList2, (item1, item2) => Tuple.Create(item1.Item1, item1.Item2 + item2.Item2)).ToList()); var avgSeq = sumSeq.Select(item => Tuple.Create(item.Item1, item.Item2 / dtListList.Count)); var dtTextList = avgSeq.Select(dt => $"{dt.Item1} : {dt.Item2:0.0}ms"); sb.Append(string.Join("\r\n", dtTextList)); //var dtList = dtListList.Last(); //var dtTextList = dtList.Select(dt => $"{dt.Item1} : {dt.Item2:0.0}ms"); //sb.Append(string.Join("\r\n", dtTextList)); } id.DrawString(sb.ToString(), InfoFont, Color.Black, this.Width - 230, 2, Color.White); }
// 커서 정보 표시 private void DrawCursorInfo(ImageDrawing id, int ofsx, int ofsy) { var ptImg = DispToImg(ptMove); int ix = (int)Math.Round(ptImg.X); int iy = (int)Math.Round(ptImg.Y); var colText = GetImagePixelValueText(ix, iy); string zoomText = GetZoomText(); string text = ($"zoom={zoomText} ({ix},{iy})={colText}").PadRight(35); var size = InfoFont.MeasureString(text); id.DrawString(text, InfoFont, Color.White, ofsx, ofsy, Color.Black); }
// 픽셀값 표시 private void DrawPixelValue(ImageDrawing id) { if (imgBuf == IntPtr.Zero) { return; } var zoom = GetZoomFactor(); if (zoom < 16 || (imgBytepp != 1 && zoom < 32)) { return; } IFont font; bool multiLine = false; if (imgBytepp == 1) { if (zoom <= 17) { font = Fonts.Ascii_05x08; } else if (zoom <= 25) { font = Fonts.Ascii_06x13; } else if (zoom <= 33) { font = Fonts.Ascii_08x16; } else { font = Fonts.Ascii_10x18; } } else { multiLine = true; if (zoom <= 33) { font = Fonts.Ascii_05x08; } else if (zoom <= 49) { font = Fonts.Ascii_06x13; } else if (zoom <= 65) { font = Fonts.Ascii_08x16; } else { font = Fonts.Ascii_10x18; } } var ptImgLT = DispToImg(Point.Empty); var ptImgRB = DispToImg((Point)Size); int ix1 = (int)Math.Round(ptImgLT.X); int iy1 = (int)Math.Round(ptImgLT.Y); int ix2 = (int)Math.Round(ptImgRB.X); int iy2 = (int)Math.Round(ptImgRB.Y); ix1 = Math.Max(ix1, 0); iy1 = Math.Max(iy1, 0); ix2 = Math.Min(ix2, imgBw - 1) + 1; // ix end exclusive iy2 = Math.Min(iy2, imgBh - 1) + 1; // iy end exclusive Action <int> IyAction = (iy) => { for (int ix = ix1; ix < ix2; ix++) { string pixelValueText = GetImagePixelValueText(ix, iy, multiLine); int colIdx = GetImagePixelValueColorIndex(ix, iy); id.DrawString(pixelValueText, font, pseudoColor[colIdx], ix - 0.5f, iy - 0.5f); } }; if (Option.UseParallelToDraw) { Parallel.For(iy1, iy2, IyAction); } else { for (int iy = iy1; iy < iy2; iy++) { IyAction(iy); } } }
public new void Invalidate() { List <Tuple <string, double> > tList = new List <Tuple <string, double> >(); tList.Add(Tuple.Create("Start", Util.GetTimeMs())); double zoom = GetZoomFactor(); IntPtr dispBuf = dib.BufPtr; int dispBw = dib.Width; int dispBh = dib.Height; IntPtr hdc = dib.Hdc; var id = new ImageDrawing(dispBuf, dispBw, dispBh, zoom, PtPan); var idWnd = new ImageDrawing(dispBuf, dispBw, dispBh); // 이미지 확대 축소 if (imgBuf == IntPtr.Zero) { ImageBoxUtil.Clear(dispBuf, dispBw, dispBh, BackColor.ToArgb(), Option.UseParallelToDraw); } else { ImageBoxUtil.DrawImageBufferZoom(imgBuf, imgBw, imgBh, imgBytepp, isImgbufFloat, dispBuf, dispBw, dispBh, PtPan.X, PtPan.Y, zoom, BackColor.ToArgb(), Option.FloatValueMax, lineDrawAction, Option.UseParallelToDraw); if (lineDrawAction == null) { idWnd.DrawString("LineDrawAction not assigned,\nso i can not display image.", InfoFont, Color.Yellow, 2, 25); } } tList.Add(Tuple.Create("DrawImageBufferZoom", Util.GetTimeMs())); // 픽셀값 표시 if (Option.UseDrawPixelValue) { DrawPixelValue(id); } tList.Add(Tuple.Create("DrawPixelValue", Util.GetTimeMs())); // ROI 표시 if (Option.UseDrawRoiRectangles) { DrawRoiRectangles(id); if (isRoiDown) { DrawRoiDown(id); } } tList.Add(Tuple.Create("DrawRoiRectangles", Util.GetTimeMs())); // 중심선 표시 if (Option.UseDrawCenterLine) { DrawCenterLine(id); } tList.Add(Tuple.Create("DrawCenterLine", Util.GetTimeMs())); // PaintBackBuffer이벤트 발생 OnPaintBackBuffer(dispBuf, dispBw, dispBh); // 여기서 사용자가 정의한 Paint이벤트 함수가 호출됨 tList.Add(Tuple.Create("OnPaintBackBuffer", Util.GetTimeMs())); // Paint이벤트 발생 using (var g = Graphics.FromHdc(hdc)) { base.OnPaint(new PaintEventArgs(g, ClientRectangle)); // 여기서 사용자가 정의한 Paint이벤트 함수가 호출됨 } tList.Add(Tuple.Create("OnPaint", Util.GetTimeMs())); // 커서 정보 표시 if (Option.UseDrawCursorInfo) { DrawCursorInfo(idWnd, 2, 2); } tList.Add(Tuple.Create("DrawCursorInfo", Util.GetTimeMs())); // 디비그 정보 표시 if (Option.UseDrawDebugInfo) { DrawDebugInfo(idWnd); } tList.Add(Tuple.Create("DrawDebugInfo", Util.GetTimeMs())); // 프런트버퍼에다 복사 dib.BitBlt(IntPtr.Zero); tList.Add(Tuple.Create("Render", Util.GetTimeMs())); // delta 계산 및 total 계산 var nextList = tList.Skip(1); List <Tuple <string, double> > dtList = nextList.Zip(tList, (next, prev) => Tuple.Create(next.Item1, next.Item2 - prev.Item2)).ToList(); dtList.Add(Tuple.Create("Total", tList.Last().Item2 - tList.First().Item2)); dtListList.Add(dtList); while (dtListList.Count > Option.TimeCheckCount) { dtListList.RemoveAt(0); } }