Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Wednesday, September 12, 2007 5:25:47 AM(UTC)

manju  
manju

Groups: Registered
Posts: 49


Hi,

Please check the below code,


AnnContainer container;
//AnnAutomationManager manager;
RasterImageViewer viewer;
RasterCodecs codecs;
AnnDesigner currentDesigner;
public Form1(string title)
{
Text = title;
Size = new Size(500, 200);

viewer = new RasterImageViewer();
viewer.TransformChanged += new EventHandler(viewer_TransformChanged);
viewer.PostImagePaint += new PaintEventHandler(viewer_PostImagePaint);
viewer.MouseDown += new MouseEventHandler(viewer_MouseDown);
viewer.MouseMove += new MouseEventHandler(viewer_MouseMove);
viewer.MouseUp += new MouseEventHandler(viewer_MouseUp);
viewer.LostFocus += new EventHandler(viewer_LostFocus);

// load an image into the viewer
RasterCodecs.Startup();
codecs = new RasterCodecs();
viewer.Image = new RasterImage(Image.FromFile("c:\\PE5.jpg"));
RasterCodecs.Shutdown();

// create and set up the container
container = new AnnContainer();
container.Bounds = new AnnRectangle(0, 0, viewer.ImageSize.Width, viewer.ImageSize.Height);
container.UnitConverter = new AnnUnitConverter(viewer.ImageDpiX, viewer.ImageDpiY);

// Create a panel with three buttons
Panel panel = new Panel();
panel.Dock = DockStyle.Left;
Controls.Add(panel);
panel.BringToFront();

// Create three buttons
Button buttonLine = new Button();
buttonLine.Click += new EventHandler(buttonLine_Click);
buttonLine.Text = "Line";
buttonLine.Dock = DockStyle.Top;
panel.Controls.Add(buttonLine);
buttonLine.BringToFront();

Button buttonInsertText = new Button();
buttonInsertText.Click += new EventHandler(buttonInsertText_Click);
buttonInsertText.Text = "Insert Text";
buttonInsertText.Dock = DockStyle.Bottom;
panel.Controls.Add(buttonInsertText);
buttonInsertText.BringToFront();

Button buttonSelect = new Button();
buttonSelect.Click += new EventHandler(buttonSelect_Click);
buttonSelect.Text = "Select";
buttonSelect.Dock = DockStyle.Left;
panel.Controls.Add(buttonSelect);
buttonSelect.BringToFront();

// Add the viewer
viewer.Dock = DockStyle.Fill;
Controls.Add(viewer);
viewer.BringToFront();

}

private void viewer_TransformChanged(object sender, EventArgs e)
{
// set up the container transformation
if (viewer.Image != null && container != null)
container.Transform = viewer.Transform.Clone();
}

private void viewer_PostImagePaint(object sender, PaintEventArgs e)
{
// draw the container and its objects on this viewer
if (viewer.Image != null && container != null)
container.Draw(e.Graphics);
}

private void buttonSelect_Click(object sender, System.EventArgs e)
{
// Select button is clicked
// cancel any draw designer running
if (currentDesigner != null && currentDesigner is AnnDrawDesigner)
{
AnnDrawDesigner drawDesigner = currentDesigner as AnnDrawDesigner;
drawDesigner.Cancel();
currentDesigner = null;
}
}

private void buttonLine_Click(object sender, System.EventArgs e)
{
// Line button is clicked

// first end any current designer (if any)
EndDesigner();

// start a new Line draw designer
AnnLineDrawDesigner lineDrawDesigner = new AnnLineDrawDesigner();

// set up the object template (a 2 pixels-wide pen)
AnnLineObject lineObject = new AnnLineObject();
lineObject.Pen = new AnnPen(Color.Red, new AnnLength(2, AnnUnit.Pixel));
lineDrawDesigner.ObjectTemplate = lineObject;

StartDrawDesigner(lineDrawDesigner);
}


private void buttonInsertText_Click(object sender, System.EventArgs e)
{

EndDesigner();

AnnTextDrawDesigner textDrawDesigner = new AnnTextDrawDesigner();
// AnnRectangleDrawDesigner rectangleDrawDesigner = new AnnRectangleDrawDesigner();

AnnTextObject text = new AnnTextObject();
text.Text = "Sandy";
text.Bounds = new AnnRectangle(50, 50, 100, 200, AnnUnit.Pixel);
text.Pen = new AnnPen(Color.Red, new AnnLength(2, AnnUnit.Pixel));
text.Brush = new AnnSolidBrush(Color.Yellow);
textDrawDesigner.ObjectTemplate = text;


StartDrawDesigner(textDrawDesigner);
}

private void EndDesigner()
{
// ends any running designer
if (currentDesigner != null)
{
if (currentDesigner is AnnEditDesigner)
{
AnnEditDesigner editDesigner = currentDesigner as AnnEditDesigner;
editDesigner.End();
}
else if (currentDesigner is AnnDrawDesigner)
{
AnnDrawDesigner drawDesigner = currentDesigner as AnnDrawDesigner;
drawDesigner.Cancel();
}
}
}

private void StartDrawDesigner(AnnDrawDesigner drawDesigner)
{
// set up the current designer
drawDesigner.Draw += new EventHandler(OnDesignerDraw);
drawDesigner.Owner = viewer;
drawDesigner.ClipCursor = true;
drawDesigner.Container = container;
currentDesigner = drawDesigner;
}

private void OnDesignerDraw(object sender, AnnDrawDesignerEventArgs e)
{
// show information on the current draw operation
Console.Write("Status: {0}, Object: {1}, Coordinates:", e.OperationStatus, e.Object.GetType().Name);
if (e.Object is AnnLineObject)
{
AnnLineObject lineObject = e.Object as AnnLineObject;
Console.WriteLine("Start Point: {0}, EndPoint: {1}", lineObject.StartPoint, lineObject.EndPoint);
}
else if (e.Object is AnnTextObject)
{
AnnTextObject textObject = e.Object as AnnTextObject;
Console.WriteLine("Bounds: {0}", textObject.Bounds);
}
}

private void viewer_MouseDown(object sender, MouseEventArgs e)
{
bool handled = false;

// see if a designer is currently running, if so, let it handle this event
if (currentDesigner != null)
handled = currentDesigner.MouseDown(e);

if (!handled)
{
// the mouse click was ! handled by a designer
// check if the click was on top of an existing object that we can start editing
AnnPoint pt = new AnnPoint(e.X, e.Y);
AnnObject obj = container.HitTest(pt, 2);
if (obj != null)
{
// yes, start the edit designer for this object
if (obj is AnnLineObject)
{
AnnLineEditDesigner lineEditDesigner = new AnnLineEditDesigner();
StartEditing(lineEditDesigner, obj, pt);
lineEditDesigner.MouseDown(e);
}
else if (obj is AnnTextObject)
{
AnnRectangleEditDesigner rectangleEditDesigner = new AnnRectangleEditDesigner();
StartEditing(rectangleEditDesigner, obj, pt);
rectangleEditDesigner.MouseDown(e);
}
}
}
}

private void StartEditing(AnnEditDesigner editDesigner, AnnObject obj, AnnPoint pt)
{
// first end any running designers
EndDesigner();

// set up the current designer
editDesigner.Edit += new EventHandler(OnDesignerEdit);
editDesigner.Owner = viewer;
editDesigner.Container = container;
editDesigner.ClipCursor = true;
editDesigner.EditObject = obj;
editDesigner.HitTestBuffer = 2;
editDesigner.ControlPointsHitTestBuffer = 2;
editDesigner.RotateModifierKey = Keys.Shift;
editDesigner.HitTestObject = obj.HitTest(pt, 2);

// set up the edit designer control points
AnnRectangleControlPoint rectangleControlPoint = new AnnRectangleControlPoint();
rectangleControlPoint.Size = new AnnSize(10, 10, AnnUnit.Pixel);
rectangleControlPoint.Pen = new AnnPen(Color.Blue, new AnnLength(1, AnnUnit.Pixel));
rectangleControlPoint.Brush = new AnnSolidBrush(Color.White);

for (int i = 0; i < editDesigner.ControlPointCount; i++)
editDesigner.ControlPoints[i] = rectangleControlPoint;

editDesigner.Start();
currentDesigner = editDesigner;
}

private void OnDesignerEdit(object sender, AnnEditDesignerEventArgs e)
{
// show information on the current draw operation
Console.Write("Object: {0}, Operation: {1}, Status: {2}, ", e.Object.GetType().Name, e.Operation, e.OperationStatus);
if (e.Operation == AnnEditDesignerOperation.MoveControlPoint)
Console.WriteLine("Control Point index: {0}", e.MoveControlPointIndex);
else
Console.WriteLine("HitTestObject: {0}", e.HitTestObject);
}

private void viewer_MouseMove(object sender, MouseEventArgs e)
{
bool handled = false;

// see if a designer is currently running, if so, let it handle this event
if (currentDesigner != null)
handled = currentDesigner.MouseMove(e);
}

private void viewer_MouseUp(object sender, MouseEventArgs e)
{
bool handled = false;

// see if a designer is currently running, if so, let it handle this event
if (currentDesigner != null)
handled = currentDesigner.MouseUp(e);
}

private void viewer_LostFocus(object sender, EventArgs e)
{
// see if a designer is currently running, if so, cancel it
if (currentDesigner != null)
currentDesigner.Cancel();
}



public void AnnDesigner_AnnDesigner(string title)
{
Form1 form = new Form1(title);
form.ShowDialog();
}

private void Form1_Load(object sender, EventArgs e)
{
AnnDesigner_AnnDesigner("san");
}


when you click on Insert Text it will draw only rectangle on image the text will not get displayed in that rectangle so please tell me what changes I will do in this so that text in rectangle will be visible and how i will get the location and height and weidth of that rectangle.
Also please tell me how should I provide rotate points to rotate that rectangle.Please replay soon.


Thanks
Manju
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Wednesday, September 12, 2007 9:59:46 PM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,328

Was thanked: 1 time(s) in 1 post(s)

Hello Manju,

Can you please enclose your code in a small working project that shows the problem, so that I can check the code?

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
#3 Posted : Wednesday, September 12, 2007 10:08:28 PM(UTC)

manju  
manju

Groups: Registered
Posts: 49


Hi,

please find the demo project attached, please tell me how to make text visible and how I will get the final location,height and width of text rectangle because i have checked it with bounding rectangle property of edit object but by that I got changed Height and width but the location remains same and how to provide rotate control points to text rectangle so that to move the text .Please reply soon.

Thanks
Manju
File Attachment(s):
WindowsApplication3.zip (2,937kb) downloaded 19 time(s).
 
#4 Posted : Monday, September 17, 2007 3:33:10 AM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,328

Was thanked: 1 time(s) in 1 post(s)

Hello,

I checked your code and found the problem. The problem is in the font size of the AnnTextObject.

To resolve this issue, try to create the AnnTextObject as follows:
+-------------------+
private void buttonInsertText_Click(object sender, System.EventArgs e)
{
           
EndDesigner();

AnnTextDrawDesigner textDrawDesigner = new AnnTextDrawDesigner();
            

AnnTextObject text = new AnnTextObject();
text.Text = "Sandy";
text.Bounds = new AnnRectangle(50, 50, 100, 200, AnnUnit.Pixel);
text.Pen = new AnnPen(Color.Red, new AnnLength(2, AnnUnit.Pixel));
text.Brush = new AnnSolidBrush(Color.Yellow);
// Define the Font size
text.Font = new AnnFont("Times New Roman", new AnnLength(16), FontStyle.Regular);
textDrawDesigner.ObjectTemplate = text;

StartDrawDesigner(textDrawDesigner);
}
+-------------------+

About the final location and bounds of the AnnTextObject, try to get the final location and bounds by adding the following code to your project:
+-----------------+
private void OnDesignerDraw(object sender, AnnDrawDesignerEventArgs e)
{

...

if ((e.Object is AnnTextObject) && (e.OperationStatus == AnnDesignerOperationStatus.End))
{
AnnTextObject textObject = e.Object as AnnTextObject;

MessageBox.Show("Bounds = " + textObject.Bounds.ToString());
MessageBox.Show("Location = " + textObject.BoundingRectangle.Location.ToString()); }  
}
+-----------------+

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2020, Yet Another Forum.NET
This page was generated in 0.583 seconds.