TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Kanimozhi Shivakumar
NA
293
156.5k
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.
private
void
frmLoadImage_Load(
object
sender, EventArgs e)
{
if
(strFileName.Trim() !=
""
)
{
readCdrFileCoordinates();
if
(blnLoadImage() ==
true
) drawAnnotator();
}
}
private
bool
blnLoadImage()
{
bool
blnRet =
true
;
try
{
// picImage.Image= null;
picImage.Refresh();
if
(System.IO.File.Exists(strImgFileName))
{
if
(strImgFileName.Substring(strImgFileName.Length - 3, 3).ToUpper() ==
"SVG"
)
{
SvgDocument svgDoc = SvgDocument.Open(strImgFileName);
svgDoc.Transforms =
new
SvgTransformCollection();
svgDoc.Transforms.Add(
new
SvgScale(1, 1));
picImage.Image = svgDoc.Draw();
}
else
{
if
(strImgFileName.Substring(strImgFileName.Length - 3, 3).ToUpper() ==
"GIF"
)
picImage.BackColor = Color.White;
else
picImage.BackColor = Color.Transparent;
Bitmap bt =
new
Bitmap(Image.FromFile(strImgFileName));
using
(Graphics g = Graphics.FromImage(bt))
{
g.DrawImage(bt, 0, 0);
}
picImage.Image = bt;
}
}
else
{
picImage.Image =
null
;
picImage.Refresh();
blnRet =
false
;
}
}
catch
(Exception ex)
{
blnRet =
false
;
MessageBox.Show(ex.HResult +
"-"
+ ex.Message +
"------> Error in loadImage"
);
}
return
blnRet;
}
private
void
drawAnnotator()
{
try
{
////Draw annotator in view mode, to load fast data
for
(
int
j = 0; j < lstCdrImgCoordinates.Count; j++)
{
Common.CdrFileCoordinates cdrCoordints =
new
Common.CdrFileCoordinates();
cdrCoordints = lstCdrImgCoordinates[j];
if
(cdrCoordints.strValue.Contains(
","
) ==
false
)
{
float
width = (
float
)(cdrCoordints.dblRightX - cdrCoordints.dblLeftX);
float
height = (
float
)(cdrCoordints.dblTopY - cdrCoordints.dblBottomY);
Point startPoint =
new
Point();
Size rectSize =
new
Size();
rectSize.Height = Convert.ToInt32(height);
rectSize.Width = Convert.ToInt32(width);
startPoint.X = Convert.ToInt32(cdrCoordints.dblLeftX);
startPoint.Y = Convert.ToInt32(cdrCoordints.dblTopY);
Rectangle rect =
new
Rectangle(startPoint, rectSize);
}
}
}
catch
(Exception ex)
{
MessageBox.Show(ex.HResult +
"-"
+ ex.Message +
"------> Error in drawAnnotator"
);
}
}
private
void
readCdrFileCoordinates()
{
try
{
string
strLine =
string
.Empty;
string
strTest =
string
.Empty;
int
intPosA;
int
intlength;
Common.CdrFileCoordinates cdrFile =
new
Common.CdrFileCoordinates();
StreamReader file =
new
StreamReader(strFileName);
while
((strLine = file.ReadLine()) !=
null
)
{
intPosA = strLine.LastIndexOf(
":"
) + 1;
intlength = strLine.Length - intPosA;
if
(strLine.Contains(
"Shape Name"
))
{
cdrFile =
new
Common.CdrFileCoordinates();
cdrFile.strShape = strLine.Substring(12, strLine.IndexOf(
"|"
) - 14);
cdrFile.strValue = strLine.Substring(intPosA, intlength);
}
else
if
(strLine.Contains(
"LeftX"
))
{
cdrFile.dblLeftX = Convert.ToDouble(strLine.Substring(7, strLine.IndexOf(
"|"
) - 7).Trim());
cdrFile.dblRightX = Convert.ToDouble(strLine.Substring(intPosA, intlength));
}
else
if
(strLine.Contains(
"Top Y"
))
{
cdrFile.dblTopY = Convert.ToDouble(strLine.Substring(7, strLine.IndexOf(
"|"
) - 7).Trim());
cdrFile.dblBottomY = Convert.ToDouble(strLine.Substring(intPosA, intlength));
}
else
if
(strLine.Contains(
"Center X"
))
{
cdrFile.dblCenterX = Convert.ToDouble(strLine.Substring(10, strLine.IndexOf(
"|"
) - 10).Trim());
cdrFile.dblCenterY = Convert.ToDouble(strLine.Substring(intPosA, intlength));
}
else
if
(strLine.Contains(
"Height"
))
{
cdrFile.dblHeight = Convert.ToDouble(strLine.Substring(10, strLine.IndexOf(
"|"
) - 10).Trim());
cdrFile.dblWidth = Convert.ToDouble(strLine.Substring(intPosA, intlength));
lstCdrImgCoordinates.Add(cdrFile);
}
}
file.Close();
}
catch
(Exception ex)
{
MessageBox.Show(ex.HResult +
"-"
+ ex.Message +
"------> Error in readCdrFileCoordinates"
);
}
}
Please any one help me out to draw the circle in exact location...
Reply
Answers (
0
)
How do I create an excel file with locked (read-only) in C#
I have a broblem with boolean (Unity)