//This below method was added by Darshan on 19-10-2015(Description given below). /// <summary> /// This method will draw the graph on the panel to the image. /// </summary> /// <param name="srcBitmap">Image name</param> public void DrawEllipseToBitmap(ref Bitmap srcBitmap, int id, Common.PicBoxSizeMode sizeMode = Common.PicBoxSizeMode.Zoom) { SolidBrush brush = new SolidBrush(Color.FromName(AnnotationVariables.annotationMarkingColor)); Common.CommonMethods _common = Common.CommonMethods.CreateInstance(); if (sizeMode == Common.PicBoxSizeMode.Zoom) { inp = new Image <Bgr, byte>(Form1.tempBm.Width, Form1.tempBm.Height); } else { inp = new Image <Bgr, byte>(Form1.pbxWidth, Form1.pbxHeight); } List <Point> TempPointArr = new List <Point>(); _common.Image = inp.ToBitmap(); _common.Height = Form1.pbxHeight; _common.Width = Form1.pbxWidth; Point actualImageRectStartPoint = _common.TranslatePointToImageCoordinates(new Point(rectangle.X, rectangle.Y), sizeMode); Point actualImageRectWidthPoint = _common.TranslatePointToImageCoordinates(new Point(rectangle.X + rectangle.Width, rectangle.Y), sizeMode); Point actualImageRectHeightPoint = _common.TranslatePointToImageCoordinates(new Point(rectangle.X, rectangle.Y + rectangle.Height), sizeMode); if (sizeMode != Common.PicBoxSizeMode.Zoom) { actualImageRectStartPoint.X = Convert.ToInt32((float)actualImageRectStartPoint.X * (float)srcBitmap.Width / (float)inp.Width); actualImageRectStartPoint.Y = Convert.ToInt32((float)actualImageRectStartPoint.Y * (float)srcBitmap.Height / (float)inp.Height); actualImageRectWidthPoint.X = Convert.ToInt32((float)actualImageRectWidthPoint.X * (float)srcBitmap.Width / (float)inp.Width); actualImageRectWidthPoint.Y = Convert.ToInt32((float)actualImageRectWidthPoint.Y * (float)srcBitmap.Height / (float)inp.Height); actualImageRectHeightPoint.X = Convert.ToInt32((float)actualImageRectHeightPoint.X * (float)srcBitmap.Width / (float)inp.Width); actualImageRectHeightPoint.Y = Convert.ToInt32((float)actualImageRectHeightPoint.Y * (float)srcBitmap.Height / (float)inp.Height); } int width = (int)Math.Sqrt(Math.Pow(((double)actualImageRectStartPoint.X - (double)actualImageRectWidthPoint.X), 2)); int height = (int)Math.Sqrt(Math.Pow(((double)actualImageRectStartPoint.Y - (double)actualImageRectHeightPoint.Y), 2)); int x, y, xCenter, yCenter; xCenter = actualImageRectStartPoint.X + width / 2; yCenter = actualImageRectStartPoint.Y + height / 2; x = actualImageRectStartPoint.X; y = actualImageRectStartPoint.Y; Bitmap bm = inp.ToBitmap(); Rectangle ellipseRectangle = new Rectangle(actualImageRectStartPoint, new Size(width, height)); Graphics g = Graphics.FromImage(srcBitmap); g.DrawEllipse(new Pen(Color.FromName(AnnotationVariables.annotationMarkingColor), 9.0f), DrawRectangle.GetNormalizedRectangle(ellipseRectangle)); //DrawAnnotationNumber(g, id); g.DrawString(id.ToString(), new Font(FontFamily.GenericSansSerif, 43.2f, FontStyle.Bold, GraphicsUnit.Pixel), brush, new PointF(xCenter - 10, y - 60)); g.Dispose(); }
/// <summary> /// Method to translate the points drawn on the screen to the actual the points are obtained from the screen and zoom factor translation is done and a convex polygon for the same points are drawn on the image saving of the image is done for debugging which is commented /// </summary> public void GetContourValue() { Common.CommonMethods _common = Common.CommonMethods.CreateInstance(); inp = new Image <Bgr, byte>(GlaucomaTool.tempBm.Width, GlaucomaTool.tempBm.Height); INTUSOFT.Custom.Controls.PictureBoxExtended temp = new INTUSOFT.Custom.Controls.PictureBoxExtended(); temp.SizeMode = PictureBoxSizeMode.Zoom; temp.Image = inp.ToBitmap(); List <Point> TempPointArr = new List <Point>(); _common.Image = temp.Image; _common.Height = GlaucomaTool.pbxHeight; _common.Width = GlaucomaTool.pbxWidth; for (int i = 0; i < this.pointArray.Count; i++) { TempPointArr.Add(_common.TranslatePointToImageCoordinates((Point)this.pointArray[i], Common.PicBoxSizeMode.Zoom)); } List <Point> TempPointArr1 = new List <Point>(); //ReorderPointList(ref TempPointArr, ref TempPointArr1);// cartesian reordering of points commented by sriram PolarReorderPointList(ref TempPointArr, ref TempPointArr1); if (this.isCup) { cupImage = inp.ToBitmap(); Graphics g = Graphics.FromImage(cupImage); g.FillPolygon(Brushes.White, TempPointArr1.ToArray()); g.Dispose(); } else { discImage = inp.ToBitmap(); Graphics g = Graphics.FromImage(discImage); g.FillPolygon(Brushes.White, TempPointArr1.ToArray()); g.Dispose(); } }
//This below method was added by Darshan on 19-10-2015(Description given below). /// <summary> /// This method will draw the graph on the panel to the image. /// </summary> /// <param name="srcBitmap">Image name</param> public void DrawLineToBitmap(ref Bitmap srcBitmap, Common.PicBoxSizeMode sizeMode = Common.PicBoxSizeMode.Zoom) { Common.CommonMethods _common = Common.CommonMethods.CreateInstance(); if (sizeMode == Common.PicBoxSizeMode.Zoom) { inp = new Image <Bgr, byte>(Form1.tempBm.Width, Form1.tempBm.Height); } else { inp = new Image <Bgr, byte>(Form1.pbxWidth, Form1.pbxHeight); } List <Point> TempPointArr = new List <Point>(); _common.Image = inp.ToBitmap(); _common.Height = inp.Width; _common.Width = inp.Height; Point actualImageLineStartPoint = _common.TranslatePointToImageCoordinates(new Point(startPoint.X, startPoint.Y), sizeMode); Point actualImageLineEndPoint = _common.TranslatePointToImageCoordinates(new Point(endPoint.X, endPoint.Y), sizeMode); if (sizeMode != Common.PicBoxSizeMode.Zoom) { actualImageLineStartPoint.X = Convert.ToInt32((float)actualImageLineStartPoint.X * (float)srcBitmap.Width / (float)inp.Width); actualImageLineStartPoint.Y = Convert.ToInt32((float)actualImageLineStartPoint.Y * (float)srcBitmap.Height / (float)inp.Height); actualImageLineEndPoint.X = Convert.ToInt32((float)actualImageLineEndPoint.X * (float)srcBitmap.Width / (float)inp.Width); actualImageLineEndPoint.Y = Convert.ToInt32((float)actualImageLineEndPoint.Y * (float)srcBitmap.Height / (float)inp.Height); } Pen pen = new Pen(Color.FromName(AnnotationVariables.annotationMarkingColor), 10); pen.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; Bitmap bm = inp.ToBitmap(); Graphics g = Graphics.FromImage(srcBitmap); g.DrawLine(pen, actualImageLineStartPoint.X, actualImageLineStartPoint.Y, actualImageLineEndPoint.X, actualImageLineEndPoint.Y); g.Dispose(); }
//This below method was added by Darshan on 19-10-2015(Description given below). /// <summary> /// This method will draw the graph on the panel to the image. /// </summary> /// <param name="srcBitmap">Image name</param> public void DrawPolygonToImage(ref Bitmap srcBitmap, int id, Common.PicBoxSizeMode sizeMode = Common.PicBoxSizeMode.Zoom) { SolidBrush brush = new SolidBrush(Color.FromName(AnnotationVariables.annotationMarkingColor)); Common.CommonMethods _common = Common.CommonMethods.CreateInstance(); int width = 0; int height = 0; if (AnnotationVariables.isGlaucomaTool) { inp = new Image <Bgr, byte>(GlaucomaTool.tempBm.Width, GlaucomaTool.tempBm.Height); if (sizeMode == Common.PicBoxSizeMode.Zoom) { inp = new Image <Bgr, byte>(GlaucomaTool.tempBm.Width, GlaucomaTool.tempBm.Height); } else { inp = new Image <Bgr, byte>(GlaucomaTool.pbxWidth, GlaucomaTool.pbxHeight); } _common.Height = GlaucomaTool.pbxHeight; _common.Width = GlaucomaTool.pbxWidth; } else { if (sizeMode == Common.PicBoxSizeMode.Zoom) { inp = new Image <Bgr, byte>(Form1.tempBm.Width, Form1.tempBm.Height); } else { inp = new Image <Bgr, byte>(Form1.pbxWidth, Form1.pbxHeight); } _common.Height = Form1.pbxHeight; _common.Width = Form1.pbxWidth; } List <Point> TempPointArr = new List <Point>(); _common.Image = inp.ToBitmap(); for (int i = 0; i < this.pointArray.Count; i++) { Point actualImageRectStartPoint = _common.TranslatePointToImageCoordinates((Point)this.pointArray[i], sizeMode); if (sizeMode != Common.PicBoxSizeMode.Zoom) { actualImageRectStartPoint.X = Convert.ToInt32((float)actualImageRectStartPoint.X * (float)srcBitmap.Width / (float)inp.Width); actualImageRectStartPoint.Y = Convert.ToInt32((float)actualImageRectStartPoint.Y * (float)srcBitmap.Height / (float)inp.Height); } TempPointArr.Add(actualImageRectStartPoint); } List <Point> TempPointArr1 = new List <Point>(); //ReorderPointList(ref TempPointArr, ref TempPointArr1);// cartesian reordering of points commented by sriram PolarReorderPointList(ref TempPointArr, ref TempPointArr1); Graphics g = Graphics.FromImage(srcBitmap); //DrawAnnotationNumber(g, id); if (this.isCup) { g.DrawPolygon(new Pen(Color.FromName(AnnotationVariables.cupColor), 3.0f), TempPointArr1.ToArray()); } else { g.DrawPolygon(new Pen(Color.FromName(AnnotationVariables.discColor), 3.0f), TempPointArr1.ToArray()); } if (!AnnotationVariables.isGlaucomaTool) { g.DrawString(id.ToString(), new Font(FontFamily.GenericSansSerif, 43.2f, FontStyle.Bold, GraphicsUnit.Pixel), brush, new PointF(TempPointArr[1].X - 55, TempPointArr[1].Y - 45)); g.DrawPolygon(new Pen(Color.FromName(AnnotationVariables.annotationMarkingColor), 9.0f), TempPointArr1.ToArray()); } g.Dispose(); }