Автор работы: Пользователь скрыл имя, 27 Мая 2013 в 04:20, курсовая работа
В настоящее время рынок программного обеспечения переполнен различными программами и редакторами, позволяющими обрабатывать и редактировать цифровые фото. Человеку, не слишком хорошо понимающему особенности тех или иных программных средств, порой очень сложно разобраться в этом многообразии софта. Однако, правильный выбор программных средств для решения конкретной задачи по обработке фотоснимков является одним из залогов успеха получения законченных фотографий.
Введение……………………………………………………………………… 5
1 Аналитический обзор литературы 7
2 Разработка алгоритма ………………………………………………………. 9
3 Разработка программного стредства 11
3.1 Описание классов 11
3.2 Диаграмма классов…………………………………………………… 16
4 Обоснование технических приемов программирования 18
5 Тестрование, эксперементальные исследования и анализ полученных результатов………………………………………………………………………...19
6 Руководство пользователя………………………………………………………28
Заключение 33
Список литературы 34
Приложение листинг программы……………..……………………………....35
Ведомость…………………………………………………………………….....
{
int x1, y1, x2, y2;
Point p = new Point();
foreach (var item in listofShapes)
{
item.SetPenColor(this.pen);
item.SetPenWidth(this.pen);
}
foreach (var item in listofShapes)
{
x1 = item.P1.X;
y1 = item.P1.Y;
x2 = item.P2.X;
y2 = item.P2.Y;
//item.SetPoint1(item.P1().X + p1.X, item.P1().Y + p1.Y);
//item.SetPoint2(item.P2().X + p2.X, item.P2().Y + p2.Y);
p.X = item.P1.X * (p2.X - p1.X) / length + p1.X;
p.Y = item.P1.Y * (p2.Y - p1.Y)/width + p1.Y;
item.P1 = p;
p.X = item.P2.X * (p2.X - p1.X) / length + p1.X;
p.Y = item.P2.Y * (p2.Y - p1.Y)/width + p1.Y;
item.P2 = p;
item.draw(grph);
p.X = x1; p.Y = y1;
item.P1 = p;
p.X = x2; p.Y = y2;
item.P2 = p;
}
}
}
}
Файл UserShapeBuilder.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using WindowsFormsApplication1;
using System.Xml.Serialization;
namespace WindowsFormsApplication1
{
[Serializable]
public class UserShapeBuilder :ShapeBuilder
{
private List<Shape> listofShapes = new List<Shape>();
private int endX, endY;
public List<Shape> Content
{
get { return listofShapes; }
set { listofShapes = value; }
}
public int EndX
{
get { return endX; }
set { endX = value; }
}
public int EndY
{
get { return endY; }
set { endY = value; }
}
public void SaveNameandList(string s, List<Shape> tmplst)
{
Point p = new Point();
int startX, startY;
startX = 32000;
startY = 32000;
endX = 0;
endY = 0;
foreach (var item in tmplst)
{
if (startX > item.P1.X)
startX = item.P1.X;
if (startX > item.P2.X)
startX = item.P2.X;
if (startY > item.P1.Y)
startY = item.P1.Y;
if (startY > item.P2.Y)
startY = item.P2.Y;
}
foreach (var item in tmplst)
{
p.X = item.P1.X - startX; p.Y = item.P1.Y - startY;
item.P1 = p;
p.X = item.P2.X - startX; p.Y = item.P2.Y - startY;
item.P2 = p;
}
foreach (var item in tmplst)
{
if (endX < item.P1.X)
endX = item.P1.X;
if (endX < item.P2.X)
endX = item.P2.X;
if (endY < item.P1.Y)
endY = item.P1.Y;
if (endY < item.P2.Y)
endY = item.P2.Y;
}
listofShapes = tmplst;
namebuilder = s;
}
public override Shape CreateShape()
{
return new UserShape(listofShapes,endX,
}
}
}
Файл Designer.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Designer : Form
{
private Form1 form1Window;
public Shape current_Shape;
private ShapeBuilder createShape;
private CircleBuilder createCircle;
private TriangleBuilder createTriangle;
private RectangleBuilder createRectangle;
private List<Shape> list_of_Shapes = new List<Shape>();
public Graphics grph;
private Pen current_pen = new Pen(Color.Black), whitepen = new Pen(Color.White);
private Point p = new Point();
public Designer(Form1 fromwindow)
{
form1Window = fromwindow;
InitializeComponent();
}
private void triangleToolStripMenuItem_
{
createShape = createTriangle;
}
private void circleToolStripMenuItem_Click(
{
createShape = createCircle;
}
private void rectangleToolStripMenuItem_
{
createShape = createRectangle;
}
private void pictureBox1_MouseDown_1(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
current_Shape = createShape.CreateShape();
p.X = e.Location.X; p.Y = e.Location.Y;
current_Shape.P1 = p;
current_Shape.P2 = p;
current_Shape.SetPenColor(
}
}
public void dr_objects()
{
list_of_Shapes.ForEach(delegat
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
current_Shape.SetPenColor(
current_Shape.draw(grph);
current_Shape.SetPenColor(
p.X = e.Location.X; p.Y = e.Location.Y;
current_Shape.P2 = p;
current_Shape.draw(grph);
this.dr_objects();
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
list_of_Shapes.Add(current_
}
private void Designer_Load(object sender, EventArgs e)
{
this.grph = this.pictureBox1.
createCircle = new CircleBuilder();
createRectangle = new RectangleBuilder();
createTriangle = new TriangleBuilder();
createShape = createRectangle;
}
private void clearToolStripMenuItem1_Click(
{
grph.Clear(Color.White);
list_of_Shapes.Clear();
}
private void SaveButton_Click(object sender, EventArgs e)
{
//menuBuilder = new MenuBuilder(textBox1.Text, form1Window.GetBox(),
form1Window.Getlistofbuiders()
form1Window.
Close();
}
}
}
Файл Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WindowsFormsApplication1;
using System.IO;
using System.Xml.Serialization;
using System.Runtime.Serialization.
using ShapeInterface;
using System.Reflection;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//this.Cursor = SetCursor.LoadCustomCursor(
}
private Shape currentShape;
private int numberPickedShape;
private bool isItTool;
private ShapeBuilder createShape;
private CircleBuilder createCircle;
private TriangleBuilder createTriangle;
private RectangleBuilder createRectangle;
private LineBuilder createLine;
private PencilBuilder createPencil;
private EraseBuilder createErase;
public Graphics grph;
public Designer designerWindow ;
private Pen current_pen = new Pen(Color.Black), whitepen = new Pen(Color.White);
private Point p = new Point();
private List<ShapeBuilder> list_of_builders = new List<ShapeBuilder>();
private List<Shape> list_of_Shapes = new List <Shape>();
private bool leftbuttondown = false;
private bool leftbuttondouble = false;
private bool shapeIsPicked = false;
private ManagerUndoRedo managerUndoRedo = new ManagerUndoRedo();
private void Form1_Load(object sender, EventArgs e)
{
this.grph = this.pictureBox1.
createCircle = new CircleBuilder();
createRectangle = new RectangleBuilder();
createTriangle = new TriangleBuilder();
createLine = new LineBuilder();
createPencil = new PencilBuilder();
createErase = new EraseBuilder();
createShape = createRectangle;
list_of_builders.Add(
list_of_builders.Add(
list_of_builders.Add(
DD.Text = "Rectangle";
isItTool = false;
current_pen.Width = 1.0F;
this.Cursor = Cursors.Cross;
}
private int CheckPickedShape(MouseEventArg
{
if (shapeIsPicked)
{
if ((e.Location.X > currentShape.P2.X - 4) && (e.Location.Y > currentShape.P2.Y - 4))
if ((e.Location.X < currentShape.P2.X + 4) && (e.Location.Y < currentShape.P2.Y + 4))
{
return 2;
}
if ((e.Location.X > currentShape.P1.X - 4 + (currentShape.P2.X - currentShape.P1.X) / 2) && (e.Location.Y > currentShape.P1.Y - 4 + (currentShape.P2.Y - currentShape.P1.Y) / 2))
if ((e.Location.X < currentShape.P1.X + 4 + (currentShape.P2.X - currentShape.P1.X) / 2) && (e.Location.Y < currentShape.P1.Y + 4 + (currentShape.P2.Y - currentShape.P1.Y) / 2))
{
return 1;
}
}
return 0;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
leftbuttondown = true;
grph.Clear(Color.White);
dr_objects();
numberPickedShape = CheckPickedShape(e);
if (numberPickedShape == 0)
{
shapeIsPicked = false;
currentShape = createShape.CreateShape();
p.X = e.Location.X; p.Y = e.Location.Y;
currentShape.P1 = p;
currentShape.P2 = p;
currentShape.SetPenColor(
currentShape.SetPenWidth(
currentShape.draw(grph);
list_of_Shapes.Add(
}
}
private void ChangePickedOutShape(MouseEven
{
if (numberPickedShape == 2)
currentShape.P2 = p;
else
{
int x1 = currentShape.P1.X, y1 = currentShape.P1.Y, x2 = currentShape.P2.X, y2 = currentShape.P2.Y;
currentShape.P2 = new Point(p.X + (x2 - x1) / 2, p.Y + (y2 - y1) / 2);
currentShape.P1 = new Point(p.X - (x2 - x1) / 2, p.Y - (y2 - y1) / 2);
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
Shape tmpShape;
labelX.Text = "X"+e.Location.X.ToString();
labelY.Text = "Y"+e.Location.Y.ToString();
if (leftbuttondown)
{
if (isItTool)
{
if (numberPickedShape != 0)
{
currentShape.SetPenColor(
currentShape.SetPenWidth(
currentShape.draw(grph);
p.X = e.Location.X; p.Y = e.Location.Y;
currentShape.SetPenColor(
ChangePickedOutShape(e, currentShape, numberPickedShape, p);
}
else
{
tmpShape = createShape.CreateShape();
tmpShape.P1 = currentShape.P2;
tmpShape.P2 = e.Location;
currentShape = createShape.CreateShape();
currentShape = tmpShape;
currentShape.SetPenColor(
currentShape.SetPenWidth(
}
currentShape.draw(grph);
list_of_Shapes.Add(
this.dr_objects();
}
else
{
currentShape.SetPenColor(
currentShape.SetPenWidth(
currentShape.draw(grph);
p.X = e.Location.X; p.Y = e.Location.Y;
currentShape.SetPenColor(
if (numberPickedShape != 0)
ChangePickedOutShape(e, currentShape, numberPickedShape, p);
else
currentShape.P2 = p;
currentShape.draw(grph);
this.dr_objects();
}
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (leftbuttondown)
{
if (!shapeIsPicked) //if ((currentShape.P1.X != currentShape.P2.X) && (currentShape.P1.Y != currentShape.P2.Y))
list_of_Shapes.Add(
else
currentShape.PickOutMe(grph);
managerUndoRedo.
}
leftbuttondown = false;
if (leftbuttondouble)
{
managerUndoRedo.Undo();
managerUndoRedo.Undo();
leftbuttondouble = false;
}
}
private void pictureBox1_MouseDoubleClick(o
{
int x1, y1, x2, y2;
leftbuttondouble = true;
for (int i = 0; i < list_of_Shapes.Count; i++)
{
if (list_of_Shapes[i].P1.X < list_of_Shapes[i].P2.X)
{
x1 = list_of_Shapes[i].P1.X;
x2 = list_of_Shapes[i].P2.X;
}
else
{
x2 = list_of_Shapes[i].P1.X;
x1 = list_of_Shapes[i].P2.X;
}
if (list_of_Shapes[i].P1.Y < list_of_Shapes[i].P2.Y)
{
y1 = list_of_Shapes[i].P1.Y;
y2 = list_of_Shapes[i].P2.Y;
}
else
{
y2 = list_of_Shapes[i].P1.Y;
y1 = list_of_Shapes[i].P2.Y;
}
if ((e.Location.X > x1) && (e.Location.Y > y1))
{
if ((e.Location.X < x2) && (e.Location.Y < y2))
{
currentShape = list_of_Shapes[i];
currentShape.PickOutMe(grph);
shapeIsPicked = true;
break;
}
}
}
}
public void dr_objects()
{
Bitmap bmp = new Bitmap(pictureBox1.Size.Width, pictureBox1.Size.Height);
Graphics grphBmp = Graphics.FromImage(bmp);
list_of_Shapes.ForEach(delegat
grph.DrawImage(bmp, 0, 0);
}
private void clearToolStripMenuItem_Click(o
{
grph.Clear(Color.White);
//managerUndoRedo.ClearStack()
list_of_Shapes.Clear();
managerUndoRedo.
Информация о работе Построение и обработка графических объектов