Exemple #1
0
        // 픽셀값 표시
        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);
                }
            }
        }
Exemple #2
0
        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);
            }
        }