Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Graphics problems

Graphics problems

Scheduled Pinned Locked Moved C#
graphicshelp
12 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Duong Tien Nam
    wrote on last edited by
    #1

    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!

    C V L 3 Replies Last reply
    0
    • D Duong Tien Nam

      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!

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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 )

      D 1 Reply Last reply
      0
      • C Christian Graus

        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 )

        D Offline
        D Offline
        Duong Tien Nam
        wrote on last edited by
        #3

        It is like you edit a canvas in Microsoft Word, I dont think I have to use DirectX :(

        C 1 Reply Last reply
        0
        • D Duong Tien Nam

          It is like you edit a canvas in Microsoft Word, I dont think I have to use DirectX :(

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          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 )

          D 1 Reply Last reply
          0
          • D Duong Tien Nam

            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!

            V Offline
            V Offline
            V 0
            wrote on last edited by
            #5

            try to put the property double buffering to true in your form properties.

            V. I found a living worth working for, but haven't found work worth living for.

            1 Reply Last reply
            0
            • C Christian Graus

              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 )

              D Offline
              D Offline
              Duong Tien Nam
              wrote on last edited by
              #6

              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...

              1 Reply Last reply
              0
              • D Duong Tien Nam

                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!

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                maybe showing the code could help us help you. :)

                Luc Pattyn [My Articles] [Forum Guidelines]

                D 1 Reply Last reply
                0
                • L Luc Pattyn

                  maybe showing the code could help us help you. :)

                  Luc Pattyn [My Articles] [Forum Guidelines]

                  D Offline
                  D Offline
                  Duong Tien Nam
                  wrote on last edited by
                  #8

                  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

                  L 1 Reply Last reply
                  0
                  • D Duong Tien Nam

                    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

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #9

                    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]

                    D 1 Reply Last reply
                    0
                    • L Luc Pattyn

                      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]

                      D Offline
                      D Offline
                      Duong Tien Nam
                      wrote on last edited by
                      #10

                      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.

                      L 1 Reply Last reply
                      0
                      • D Duong Tien Nam

                        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.

                        L Offline
                        L Offline
                        Luc Pattyn
                        wrote on last edited by
                        #11

                        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]

                        D 1 Reply Last reply
                        0
                        • L Luc Pattyn

                          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]

                          D Offline
                          D Offline
                          Duong Tien Nam
                          wrote on last edited by
                          #12

                          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 :((

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups