Kanimozhi Shivakumar

Kanimozhi Shivakumar

  • NA
  • 293
  • 142.4k

Draw circles based on co ordinates of textbox in corelDraw

Jul 17 2018 5:08 AM
Hi All,
 
I have corel draw files(.cdr). From C# I have to read corel draw file and find the text box location co ordinates , based on the co ordinates I should draw a circle on the image file.
 
 
 
The above Fig. is my input Corel draw file(.cdr). In this each numbers located inside the text box..
The co ordinates of the text box already i have got and it will write the same into .txt file with the cdr file name. 
The image version of this file i will select from my application and the program should read respective co ordinates from the text file and it should draw the circles for the number values.. Find below image..
 
 Problem is the image in the corel draw file is starting position is coming in negative.. the 0,0 position will be my center of the corel draw file.. So I am getting the circles in some other location. 
 
Here is the code that I have written for draw the circle. 
  1. private void frmLoadImage_Load(object sender, EventArgs e)  
  2.        {  
  3.            if (strFileName.Trim() != "")  
  4.            {  
  5.                readCdrFileCoordinates();  
  6.                if (blnLoadImage() == true) drawAnnotator();  
  7.            }  
  8.        }  
  9.   
  10.        private bool blnLoadImage()  
  11.        {  
  12.            bool blnRet = true;  
  13.            try  
  14.            {  
  15.                  
  16.               // picImage.Image= null;  
  17.                picImage.Refresh();  
  18.                if (System.IO.File.Exists(strImgFileName))  
  19.                {  
  20.                    if (strImgFileName.Substring(strImgFileName.Length - 3, 3).ToUpper() == "SVG")  
  21.                    {  
  22.                        SvgDocument svgDoc = SvgDocument.Open(strImgFileName);  
  23.                        svgDoc.Transforms = new SvgTransformCollection();  
  24.                        svgDoc.Transforms.Add(new SvgScale(1, 1));  
  25.                        picImage.Image = svgDoc.Draw();  
  26.                    }  
  27.                    else  
  28.                    {  
  29.                        if (strImgFileName.Substring(strImgFileName.Length - 3, 3).ToUpper() == "GIF")  
  30.                            picImage.BackColor = Color.White;  
  31.                        else  
  32.                            picImage.BackColor = Color.Transparent;  
  33.   
  34.                        Bitmap bt = new Bitmap(Image.FromFile(strImgFileName));  
  35.                        using (Graphics g = Graphics.FromImage(bt))  
  36.                        {  
  37.                            g.DrawImage(bt, 0, 0);  
  38.                        }  
  39.                        picImage.Image = bt;  
  40.                    }  
  41.   
  42.                }  
  43.                else  
  44.                {  
  45.                    picImage.Image = null;  
  46.                    picImage.Refresh();  
  47.                    blnRet = false;  
  48.                }  
  49.            }  
  50.            catch (Exception ex)  
  51.            {  
  52.                blnRet = false;  
  53.                MessageBox.Show(ex.HResult + "-" + ex.Message + "------> Error in loadImage");  
  54.            }  
  55.            return blnRet;  
  56.        }  
  57.        private void drawAnnotator()  
  58.        {  
  59.            try  
  60.            {  
  61.   
  62.                ////Draw annotator in view mode, to load fast data  
  63.                for (int j = 0; j < lstCdrImgCoordinates.Count; j++)  
  64.                {  
  65.                    Common.CdrFileCoordinates cdrCoordints = new Common.CdrFileCoordinates();  
  66.                    cdrCoordints = lstCdrImgCoordinates[j];  
  67.                    if (cdrCoordints.strValue.Contains(",") == false)  
  68.                    {  
  69.                        float width = (float)(cdrCoordints.dblRightX - cdrCoordints.dblLeftX);  
  70.                        float height = (float)(cdrCoordints.dblTopY - cdrCoordints.dblBottomY);  
  71.                        Point startPoint = new Point();  
  72.                        Size rectSize = new Size();  
  73.                        rectSize.Height = Convert.ToInt32(height);  
  74.                        rectSize.Width = Convert.ToInt32(width);  
  75.                        startPoint.X = Convert.ToInt32(cdrCoordints.dblLeftX);  
  76.                        startPoint.Y = Convert.ToInt32(cdrCoordints.dblTopY);  
  77.                        Rectangle rect = new Rectangle(startPoint, rectSize);  
  78.                         
  79.                    }                     
  80.                }  
  81.            }  
  82.            catch (Exception ex)  
  83.            {  
  84.                MessageBox.Show(ex.HResult + "-" + ex.Message + "------> Error in drawAnnotator");  
  85.            }  
  86.        }  
  87.   
  88.        private void readCdrFileCoordinates()  
  89.        {  
  90.            try  
  91.            {  
  92.                string strLine = string.Empty;  
  93.                string strTest = string.Empty;  
  94.                int intPosA;  
  95.                int intlength;  
  96.                Common.CdrFileCoordinates cdrFile = new Common.CdrFileCoordinates();  
  97.                StreamReader file = new StreamReader(strFileName);  
  98.                while ((strLine = file.ReadLine()) != null)  
  99.                {  
  100.                    intPosA = strLine.LastIndexOf(":") + 1;  
  101.                    intlength = strLine.Length - intPosA;  
  102.   
  103.                    if (strLine.Contains("Shape Name"))  
  104.                    {  
  105.                        cdrFile = new Common.CdrFileCoordinates();  
  106.                        cdrFile.strShape = strLine.Substring(12, strLine.IndexOf("|") - 14);  
  107.                        cdrFile.strValue = strLine.Substring(intPosA, intlength);  
  108.                    }  
  109.                    else if (strLine.Contains("LeftX"))  
  110.                    {  
  111.                        cdrFile.dblLeftX = Convert.ToDouble(strLine.Substring(7, strLine.IndexOf("|") - 7).Trim());  
  112.                        cdrFile.dblRightX = Convert.ToDouble(strLine.Substring(intPosA, intlength));  
  113.                    }  
  114.                    else if (strLine.Contains("Top Y"))  
  115.                    {  
  116.                        cdrFile.dblTopY = Convert.ToDouble(strLine.Substring(7, strLine.IndexOf("|") - 7).Trim());  
  117.                        cdrFile.dblBottomY = Convert.ToDouble(strLine.Substring(intPosA, intlength));  
  118.                    }  
  119.                    else if (strLine.Contains("Center X"))  
  120.                    {  
  121.                        cdrFile.dblCenterX = Convert.ToDouble(strLine.Substring(10, strLine.IndexOf("|") - 10).Trim());  
  122.                        cdrFile.dblCenterY = Convert.ToDouble(strLine.Substring(intPosA, intlength));  
  123.                    }  
  124.                    else if (strLine.Contains("Height"))  
  125.                    {  
  126.                        cdrFile.dblHeight = Convert.ToDouble(strLine.Substring(10, strLine.IndexOf("|") - 10).Trim());  
  127.                        cdrFile.dblWidth = Convert.ToDouble(strLine.Substring(intPosA, intlength));  
  128.                        lstCdrImgCoordinates.Add(cdrFile);  
  129.                    }  
  130.                }  
  131.   
  132.                file.Close();  
  133.   
  134.            }  
  135.            catch (Exception ex)  
  136.            {  
  137.                MessageBox.Show(ex.HResult + "-" + ex.Message + "------> Error in readCdrFileCoordinates");  
  138.   
  139.            }  
  140.        }  
 Please any one help me out to draw the circle in exact location...