Graphics problems
-
I am coding a program that drawing shapes in canvas. Shapes can move, rotate, resize and group together. I tried many ways (using Matrix...) but it still slow and not accuracy (due to rotate action). Anybody knows any program do like me or any document about this problems, help me!!!! Thank for your help!
-
I am coding a program that drawing shapes in canvas. Shapes can move, rotate, resize and group together. I tried many ways (using Matrix...) but it still slow and not accuracy (due to rotate action). Anybody knows any program do like me or any document about this problems, help me!!!! Thank for your help!
If they are moving, you should be using DirectX
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
If they are moving, you should be using DirectX
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
It is like you edit a canvas in Microsoft Word, I dont think I have to use DirectX :(
-
It is like you edit a canvas in Microsoft Word, I dont think I have to use DirectX :(
OK, it depends, you didn't describe it well, if it's just simple drawing. In that case, it's impossible to say much, based on your vague descriptions. Of course, Word is written in C, so it's always going to be faster than C#. I have written plenty of paint programs in C# tho. It depends, if you have a lot of moving objects, as you implied, then it's not like Word, and you need DX to do it well.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
I am coding a program that drawing shapes in canvas. Shapes can move, rotate, resize and group together. I tried many ways (using Matrix...) but it still slow and not accuracy (due to rotate action). Anybody knows any program do like me or any document about this problems, help me!!!! Thank for your help!
-
OK, it depends, you didn't describe it well, if it's just simple drawing. In that case, it's impossible to say much, based on your vague descriptions. Of course, Word is written in C, so it's always going to be faster than C#. I have written plenty of paint programs in C# tho. It depends, if you have a lot of moving objects, as you implied, then it's not like Word, and you need DX to do it well.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
It's slow and not accuracy not because of my drawing method (i use double buffer and other fast techique to draw) but because of the transformation agorithyms. I searched the Internet but dont see anything...
-
I am coding a program that drawing shapes in canvas. Shapes can move, rotate, resize and group together. I tried many ways (using Matrix...) but it still slow and not accuracy (due to rotate action). Anybody knows any program do like me or any document about this problems, help me!!!! Thank for your help!
maybe showing the code could help us help you. :)
Luc Pattyn [My Articles] [Forum Guidelines]
-
maybe showing the code could help us help you. :)
Luc Pattyn [My Articles] [Forum Guidelines]
OK, but it is so BIG :( This is my main class of shape, I hope it's not very complicated to learn
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; using EZDesignerCore.ShapeAttribute; using EZDesignerCore.ShapeApperance; using Utils.GraphicsUtils; namespace EZDesignerCore.Shape { public abstract class AbstractShape : ICloneable, IDisposable { #region properties protected string _name; public string Name { get { return _name; } set { _name = value; } } protected string _text; public string Text { get { return _text; } set { _text = value; } } protected RectangleF _border; public RectangleF Border { get { return _border; } } public virtual PointF Location { get { return _border.Location; } set { _border.Location = value; } } public virtual SizeF Size { get { return _border.Size; } set { _border.Size = value; } } protected Spot _spot; public Spot Spot { get { return _spot; } } protected Apperance _apprerance; public Apperance Apprerance { get { return _apprerance; } } protected Restriction _restriction; public Restriction Restriction { get { return _restriction; } } protected State _state; internal State State { get { return _state; } set { _state = value; } } protected float _rotateDegree; public float RotateDegree { get { return _rotateDegree; } set { _rotateDegree = value; } } protected TextBox _editTextBox; public TextBox EditTextBox { get { return _editTextBox; } } #endregion PointF _startPoint = PointF.Empty; Control _control = null; Graphics _graphics = null; GraphicsPath _path; GraphicsPath _oldPath = null; protected float[] _childShapeRotateDegrees; #region constructor public AbstractShape() { _spot = new Spot(); _apprerance = new Apper
-
OK, but it is so BIG :( This is my main class of shape, I hope it's not very complicated to learn
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; using EZDesignerCore.ShapeAttribute; using EZDesignerCore.ShapeApperance; using Utils.GraphicsUtils; namespace EZDesignerCore.Shape { public abstract class AbstractShape : ICloneable, IDisposable { #region properties protected string _name; public string Name { get { return _name; } set { _name = value; } } protected string _text; public string Text { get { return _text; } set { _text = value; } } protected RectangleF _border; public RectangleF Border { get { return _border; } } public virtual PointF Location { get { return _border.Location; } set { _border.Location = value; } } public virtual SizeF Size { get { return _border.Size; } set { _border.Size = value; } } protected Spot _spot; public Spot Spot { get { return _spot; } } protected Apperance _apprerance; public Apperance Apprerance { get { return _apprerance; } } protected Restriction _restriction; public Restriction Restriction { get { return _restriction; } } protected State _state; internal State State { get { return _state; } set { _state = value; } } protected float _rotateDegree; public float RotateDegree { get { return _rotateDegree; } set { _rotateDegree = value; } } protected TextBox _editTextBox; public TextBox EditTextBox { get { return _editTextBox; } } #endregion PointF _startPoint = PointF.Empty; Control _control = null; Graphics _graphics = null; GraphicsPath _path; GraphicsPath _oldPath = null; protected float[] _childShapeRotateDegrees; #region constructor public AbstractShape() { _spot = new Spot(); _apprerance = new Apper
Hi, yes it is big, and that was just the one abstract class... my first impression is you create a lot of matrix objects, and you try to do all the transformations (translation, rotation) yourself. So it is my guess your app is repainting fine (e.g. when resizing the form), but is slow when changing a shape (moving/rotating/whatever). For one, I would give each shape one instance of Matrix, and Reset it when a new matrix is needed, rather than creating matrix instances all the time. But overall I think I would do it all differently: have each shape remember its properties (size, color, whatever) and also its translation and rotation, then use the transformations offered by Graphics in the paint handler itself. As a result: 1) methods such as Move() would become very simple, they just accumulate translation, but dont modify all the coordinates. 2) method draw() for one shape becomes something like: g.ScaleTransform(...); g.TranslateTransform(...); g.RotateTransform(...); NowDrawTheOriginalShape(); I realize this is quite a change from what you have, and I would suggest you perform some small experiment before changing everything... As a last thought, you may want to try repainting only the part of your drawing that has changed, by using Control.Invalidate(Rectangle/Region). :)
Luc Pattyn [My Articles] [Forum Guidelines]
-
Hi, yes it is big, and that was just the one abstract class... my first impression is you create a lot of matrix objects, and you try to do all the transformations (translation, rotation) yourself. So it is my guess your app is repainting fine (e.g. when resizing the form), but is slow when changing a shape (moving/rotating/whatever). For one, I would give each shape one instance of Matrix, and Reset it when a new matrix is needed, rather than creating matrix instances all the time. But overall I think I would do it all differently: have each shape remember its properties (size, color, whatever) and also its translation and rotation, then use the transformations offered by Graphics in the paint handler itself. As a result: 1) methods such as Move() would become very simple, they just accumulate translation, but dont modify all the coordinates. 2) method draw() for one shape becomes something like: g.ScaleTransform(...); g.TranslateTransform(...); g.RotateTransform(...); NowDrawTheOriginalShape(); I realize this is quite a change from what you have, and I would suggest you perform some small experiment before changing everything... As a last thought, you may want to try repainting only the part of your drawing that has changed, by using Control.Invalidate(Rectangle/Region). :)
Luc Pattyn [My Articles] [Forum Guidelines]
I understand your idea that create the transformation status in each shape instance, for example:
float _scaleOffsetX; float _scaleOffsetY; float _rotateAngle; float _movingOffsetX; float _movingOffsetY;
and then use this information to draw the shape. But did you notice my_border
field? It is the bound of the shape. Client will use it to determine the shape's position and size, so it has to change when any transformation of the shape has done. The problem is when you rotate the shape, you have to re-calculate the_border
again and of course its not accuracy. I know you and I is so close to the final solution, but it's still the gap... I will think about your solution more carefully. -
I understand your idea that create the transformation status in each shape instance, for example:
float _scaleOffsetX; float _scaleOffsetY; float _rotateAngle; float _movingOffsetX; float _movingOffsetY;
and then use this information to draw the shape. But did you notice my_border
field? It is the bound of the shape. Client will use it to determine the shape's position and size, so it has to change when any transformation of the shape has done. The problem is when you rotate the shape, you have to re-calculate the_border
again and of course its not accuracy. I know you and I is so close to the final solution, but it's still the gap... I will think about your solution more carefully.Yes, you are right you need the final coordinates to support shape selection... I have to think about this. Can you confirm my assumption: "So it is my guess your app is repainting fine (e.g. when resizing the form), but is slow when changing a shape (moving/rotating/whatever)." Can you give a quantization on "slow drawing" ? And how many shapes are involved then ? Please also show the draw method for a simple specific shape. I am particularly interested in how you repaint (or let the system repaint) your drawing. :)
Luc Pattyn [My Articles] [Forum Guidelines]
-
Yes, you are right you need the final coordinates to support shape selection... I have to think about this. Can you confirm my assumption: "So it is my guess your app is repainting fine (e.g. when resizing the form), but is slow when changing a shape (moving/rotating/whatever)." Can you give a quantization on "slow drawing" ? And how many shapes are involved then ? Please also show the draw method for a simple specific shape. I am particularly interested in how you repaint (or let the system repaint) your drawing. :)
Luc Pattyn [My Articles] [Forum Guidelines]
Yes, its fast drawing, but not as fast as Word does. I just use and old-fashion double-buffer drawing techique. For object moving, I use GDI rubberband line and curve to draw. It not good for now, fast on drawing rectangle, but for ellipse, I have to flatten the graphics path, so it's extremly slow when drawing moving ellipse. I will show you the code (or even send mail to you all the source code) the next Monday, because I don't bring code to home and today is Saturday :D Anyway, do you interest of building a canvas component that can draw and transform shapes, group shapes, support zooming, ect or know any body experienced about this?...... I'm stuck on this now because I working alone :((