Drawing thousands of shapes performance

Hi
I'm developing an applet which opens a JFrame to show a map made of thousands of shapes (rectangles and arcs).
I need to scroll and zoom that map and because of this I need to redraw it every time the user do something.
I tried different kind of optimization but the paint process remains very slow.
At the moment I'm drawing inside the paint method of my JViewport subclass and cycling through a Vector containing my shapes.
What can I do to speed it up?

Try setting rendering hints as follows:
KEY_ALPHA_INTERPOLATION=VALUE_ALPHA_INTERPOLATION_SPEED
KEY_ANTIALIASING=VALUE_ANTIALIAS_OFF
KEY_TEXT_ANTIALIASING=VALUE_TEXT_ANTIALIAS_OFF
KEY_COLOR_RENDERING=VALUE_COLOR_RENDER_SPEED
KEY_RENDERING=VALUE_RENDER_SPEED
This can be done by calling
((Graphics2D) g).setRenderingHint( hintKey, hintValue )
inside your paint method.
I've been working on a similar problem and setting the Antialiasing rendering hint to off noticably sped things up.
Unfortunately I've run into issues with it (see http://forum.java.sun.com/thread.jspa?threadID=5256286&tstart=0)
-Ben

Similar Messages

  • Using pen tool to draw a particular shape...

    Hi all,
    I'm pretty new to Illustrator and just wanted some advice.
    I'm using the pen tool to try and draw a specific shape () but finding it hard trying to 'smooth' out the points where I connect my lines.
    The pen tool can't draw this all in one go, so when I try to do it in several stages, the lines don't connect up smoothly so it looks a bit... rubbish.
    Anyone got any tips or how to do this simply? Sorry if this is a total idiotic question but, I'm trying...!
    Cheers

    Somehow your picture won't show.

  • Draw a smooth shape out of point array where points are in arbitrary order

    hi folks,
    I got a little problem I just can't get figured out:
    - there's an array of points (x,y)
    - the points inside this array are arbitrary
    - now I need to find out which points define the outermost shape
    - all other points that are inside this outermost shape may not be used
    - and finally the shape should be smooth...
    a picture of what I mean is to see here:
    http://www.student-zw.fh-kl.de/~chgr0001/tmp/shape.htm
    I wonder if there's a method in Java2D to do this?!
    thanks for your help!

    well,
    it's about a class that draws an area based on coordinates out of a database.
    These coordinates are originally from a GPS device and hold information about public WLANs. If someone walked around with his GPS and found WLAN data, this data together with the according GPS coordinates is stored in certain fractions of time.
    Now my problem is that I want to present the areas, where you can get a WLAN link, on a map. To do so, I want to draw the outermost shape of a "walkaround with my GPS" session and colorize it with the average link quality.
    Furthermore I like to have that shape smooth.
    I would appreciate any hints on how to proceed and which methods of which classes are useful to do so.

  • Trying to draw a diamond shape from a shape - Please help !!!

    Hi,
    I am trying to draw a diamond shape from a custom shapes library but having a hard time getting it to shape accurately, the shape I am trying to draw should look like this :
    If someone can teach me some photoshop techniques as to how to get all the angles reshaped accurately using some photoshop tools that will be great or if you can do it in my project file that will help too, the project psd file can be downloaded from here : http://tonyalepski.heliohost.org/Diamond.psd
    Your help would be really really appreciated.
    Thank you very much !!
    Tonya.

    Your diamond looked like it was square to me. So I centered your diamond over your canvas add a vertical  guide at 50%. Measured your square to be 190 PX  Dragged out a 190 PX square shape no fill 1 px red stroke.  Transformed the shape rotating it 45 degrees and moved it up to align with your diamond.   Dragged out a horizontal guide to match your diamond cut. Used the Pen tool to add two control points the square shape. and then use the pen tool to delete the top control point then convert control point tool to convert the two added control points.
    http://www.mouseprints.net/old/dpr/Diamond.psd

  • Drawing Custom Curves, Shapes, S Shapes, etc.?

    How do I draw symmetric curves, custom shapes, S shapes, etc?
    I am a beginner, and I have PSE 6.  I can upgrade to version 8 or use plugins if necessary.  I’ve been googling this, but is the pencil the same as the pen?  Where are the Paths options?
    -->  My question is I am wanting to create custom shapes.  For example, a half circle curve, or an S shape.  How do I do that? I’d rather not use the Marquee tool. 
    Attached is an example of a curve that I want to reproduce.
              Thanks for any help.

    multiplexed2 wrote:
    How do I draw symmetric curves, custom shapes, S shapes, etc?
    I am a beginner, and I have PSE 6.  I can upgrade to version 8 or use plugins if necessary.  I’ve been googling this, but is the pencil the same as the pen?  Where are the Paths options?
    -->  My question is I am wanting to create custom shapes.  For example, a half circle curve, or an S shape.  How do I do that? I’d rather not use the Marquee tool. 
    Attached is an example of a curve that I want to reproduce.
              Thanks for any help.
    No, the pen tool is only in Photoshop. The best you can do in Elements is download shapes that have been made in Photoshop or draw out a shape and either add or subtract from the shape. You don't have a paths palette either although they exist just not accessible as in Photoshop.  You'd have to save the shape file for reuse as you can't define custom shapes in Elements.
    Type  custom shapes Photoshop and you will probably find the shape you need in one of the many freeware sets out there. They'll say for Photoshop but you can install and use them in Elements.
    For the shape of the .bmp file you posted, you can cut a rectangle shape with a circle.
    1. Draw out a rectangle with the rectangle shape tool.
    2. Press the subtract icon in the options bar.
    3. Draw out a circle to remove the unwanted area.
    4. Save the file as a PSD with a name you can remember so you can use it whenever needed.
    Note: The shape will be still be vector provided you saved as a PSD so it can be resized without degrading it.
    If you hover over the icons, tool tips will display telling what each one does. Here's an image of the icons you're looking for in the options bar in step #2.
    Example of shape cutting...path lines are present because I haven't clicked away from the layer before taking the screen shot but useful as it shows how I cut the shape. To get the curve centered, it would be helpful to add some grids. I didn't use them in the image below and you can see I'm a little off center.

  • Drawing different geometric shapes in flex

    Hi
    Can I know how to draw different geometric shapes(like square, polygon,rhombus) in flex and I should be able to calculate its x,y co-ordinates...
    Let me know if any examples are there...
    Thanks n Regards
    Aruna.S.N.

    Rob
    1. The Shapes menu is on the toolbar.
    Pull down the menu and choose the pentagon shape. That has a sliding controller that lets you choose the number of sides.
    2. 30°? which is +option shift 8+
    Peter

  • Drawing like ball shapes

    hi all,
    it is possible to draw Like ball shapes using java2D(it looks like ball)?plz help me.
    thanks in advance
    bye
    kishore naidu

    (it looks like ball)?for a flat circle you can usepublic void paintComponent(Graphics g) {
       g.setColor(Color.red);
       g.fillOval(x,y,r,r);
    }is this what you mean?
    asjf

  • Draw a strokeless shape with pen tool?

    Is it possible to draw a strokeless shape with the pen tool (as in Illustrator)?
    It is quite tedious to have to go back and remove strokes from my shapes.... especially since I can't see how to do it without clicking on each segment and hitting "delete"!
    Thanks!

    Select the entire shape with the strokes and go to the Properties Inspector or Tools Panel and select no stroke.
    Hope this helps!
    Quynh
    Flash Pro QA

  • How to draw draggable dimaont shape

    Hello all as part of a flowchart editor program i wand to be able to draw a diamont shape to the screen i have done that with code i found on line this is the code:
    GeneralPath shape = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
                shape.moveTo(pref.width / 2, 0);
                shape.lineTo(pref.width, pref.height / 2);
                shape.lineTo(pref.width / 2, pref.height);
                shape.lineTo(0, pref.height / 2);
                shape.lineTo(pref.width / 2, 0);
                RomvusHolder.addElement(shape);
                g2.draw(shape);the problem is that i want to draw the shape at the position the user presses the mouse and not at the upper left corner (as it does know), also i want to be able to fill the shape with color and to be able to drag it with the mouse. Any suggestion? thanks in advanced maxsap

    You can get the mouse poition with MouseInfo.

  • Best way to draw thousands of graphic objects on the screen

    Hello everybody, I'm wanting to develop a game where at times thousands of graphic objects are displayed on-screen. What better way to do this in terms of performance and speed?
    I have some options below. Do not know if the best way is included in these options.
    1 - Each graphical object is displayed on a MovieClip or Sprite.
    2 - There is a Bitmap that represents the game screen. All graphical objects that are displayed on screen have your images stored in BitmapData. Then the Bitmap that represents the game screen copies for themselves the BitmapData of graphical objects to be screened, using for this bitmapData.copyPixels (...) or BitmapData.draw  (...). The Bitmap that represents the screen is added to the stage via addChild (...).
    3 - The graphical objects that are displayed on screen will have their images drawn directly on stage or in a MovieClip/Sprite added to this stage by addChild (...). These objects are drawn using the methods of the Graphics class, as beginBitmapFill and beginFill.
    Recalling that the best way probably is not one of these 3 above.
    I really need this information to proceed with the creation of my game.
    Please do not be bothered with my English because I'm using Google translator.
    Thank you in advance any help.

    Thanks for the information kglad. =)
    Yes, my game will have many objects similar in appearance.
    Some other objects will use the same image stored, just in time to render these objects is that some effects (such as changing the colors) will be applied in different ways. But the picture for them all is the same.
    Using the second option, ie, BitmapDatas, which of these two methods would be more efficient? copyPixels or draw?
    Thank you in advance any help. =D

  • Trying to draw a 2D shape, but Graphics2D is null, what am I doing wrong?

    At this point, I just want a shape to appear. But when I call draw(...), I get a NullPointer. Turns out when I call getGraphics() on the input JFrame (which does show up properly when the rest is commented out), I get nothing. Maybe it's the casting, I don't know enough about this issue to really say. If anyone out there has worked with 2D primitives and can shed some light on the problem, I would appreciate it.
    Thanks for any help.
    public class BatteryDisplay extends JPanel {
         Graphics2D g2d;
         Rectangle2D.Double rect1;
         JFrame jf;
         public BatteryDisplay(JFrame jf)
              this.jf = jf;
                    // Is there another way to get the graphics object?
              g2d = (Graphics2D) jf.getGraphics();
              createRectangle();
              drawRectangle();
         public void createRectangle()
              rect1 = new Rectangle2D.Double(100,100,200,50);
              System.out.println(rect1.height);
                    // The next line returns the NullPointer, so g2d is NOT initalized
              System.out.println(g2d);
         public void drawRectangle()
              this.g2d.draw(rect1);
    }

    Your painting functions should be initiated from an overridden paintComponent, not from the constructor. A graphics object will be provided to you there.
    [http://java.sun.com/docs/books/tutorial/uiswing/painting/index.html]

  • It seems a bug of as3 when using BitmapData.draw for a shape which is masked with another shape

    This is the code of my document class:
    public class FirstMask extends Sprite
      private var maskedShape:Shape;
      public function FirstMask() {
       init();
      private function init():void {
       maskedShape = new Shape();
       addChild(maskedShape);
       maskedShape.graphics.beginFill(0xff0000);
       maskedShape.graphics.drawRect(0,0,80,80);
       maskedShape.graphics.endFill();
       var maskShape:Sprite=new Sprite();
       maskShape.graphics.beginFill(0x000000);
       maskShape.graphics.drawRect(0, 0, 20,20);
       maskShape.graphics.endFill();
       maskedShape.mask=maskShape;
       var bmd:BitmapData=new BitmapData(80,80);
       bmd.draw(maskedShape);
    When I do not use the bmd to draw the maskedShape,everything is ok.When I do that,it seems the maskShape is auto-transformed including its position and size.As a result,I can not see the maskedShape unless I adjusted the IE size.Can anybody tell me why?
    ps:If I set this.stage.align=StageAlign.TOP_LEFT; I can see the small scaled maskedShape.If I add the maskedShape to the displaylist ,everythis is ok.But Why drawing has the effect on the drawn shape?

    Thanks again.But the "draw" itself is all right.
    After " bmd.draw(maskedShape);",I code:
       var bm:Bitmap=new Bitmap(bmd);
       bm.x=100;
       bm.y=0;
       addChild(bm);
    The bm can be shown.
    So to make it clear,I print the screen:
    1.No"mask" No "draw" at all.
    2."mask" without "draw"
    3."mask"and then "draw"---the IE shows nothing
    4.If I drag the IE,adjust its size,then I can see a little thing on the top-left.
    confusing...
    PS:If I run the code as "air application",it seems all right.

  • Draw line and shapes

    I have a small problem...cos i have like one class that extends JFrame but i have one JPanel on which i would like to draw some shapes...but i dont know how...cos i tried to rewrite paint method but it does not work...if someone would please post me a simple example...on how to do that...thnx

    This is slightly barebones, but it should do. It also has some less relevant code. Here's my JFrame (or the interesting parts):
    public class MainWindow
         extends JFrame
         private PaintLayout layout;//My custom Layout, not required
         private Container c;
         public MainWindow()
              //Bind the layout and Container c for future use
         layout = new PaintLayout();
         c = getContentPane();
         c.setLayout(layout);
    //These are useful if you want to know what space is getting chopped out
         it = c.getInsets().top;
         ib = c.getInsets().bottom;
              il = c.getInsets().left;
              ir = c.getInsets().right;
         GameBoard board = new GameBoard();
    layout.addLayoutComponent(board, 0+il, 0+it, 720, 480);//Custom add function for my custom Layout
    c.add(board);//Very useful and important
    Followed by the code of interest in my JPanel:
    public class GameBoard
         extends JPanel
         implements MouseListener, MouseMotionListener
         public GameBoard()
              this.addMouseListener(this);
              this.addMouseMotionListener(this);
         public void paint(Graphics g)
    g.setColor(new Color(0, 127, 0));
    g.fillRect(0,0,this.getWidth(),this.getHeight());
         public void mouseClicked(MouseEvent arg0)
              int x = arg0.getX(), y = arg0.getY();
              System.out.print("X: "+x+" Y: "+y+"; X: "+x/10/12+"'"+(x/10)%12+"\" Y: "+y/10/12+"'"+(y/10)%12+"\";\n");
    Have fun with that.

  • Trouble with VI for drawing an arbitrary shape using mouse control.

    I have attached the vi which i am really struggling with. Basically, i want to select n points using the mouse clicks and then draw a shape connecting those points by using 
    a boolean LED to move smothely through points in order and back to the first point. i have noticed that when the gradient between two is negative the LED goes in opposite direction unexpectedly.
    I really dont know how to fix this.
    Any help will be appreciated.
    Solved!
    Go to Solution.
    Attachments:
    arbitrarymovement.vi ‏24 KB

    Hello gurucode
    I have made the changes in the VI, once again to the best of my understanding. 
    Problems with the code (if you have a straight line parallel to the y axis the movement is super fast)
    i've left that one for you to play around with set to your liking 
    PS. If you have some free time, you may want to look into design patterns, they are pretty cool and help manage your code better 
    Links :
    http://www.ni.com/white-paper/7595/en/
    http://www.ni.com/white-paper/3023/en/
    Derick Mathew
    Attachments:
    arbitrarymovementfinal.vi ‏26 KB

  • Draw an visio shape as an .vdx file and render the same in a IE browser

    I had generated an Visio Diagrams getting input from the excel file and stored it in an local path.
    private void DynamicVisio_Load(object sender, EventArgs e)
                string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= 'c:\\Test\\FullData3.xls';Extended Properties='Excel 8.0;HDR=Yes;'";
                string sQuery = "select * from [Customer1_Server$] order by Name";
                DataSet objExcelDS = new DataSet();
                OleDbDataAdapter objDA = new OleDbDataAdapter(sQuery, strConn);
                objDA.Fill(objExcelDS);
                double dblX1 = 0.5d;
                double dblY1 = 10.3d;
                double dblX2 = 2.258d;
                double dblY2 = 6.8d;
                String sText = "";
                String sFilePath = "";
                String sDisk = "";
                String[] sArray;
                String[] separators = { "," };
                String sPicturePath = "C:\\Test\\test.png";
                String sIPRangeValue = "";
                Visio.Application objVApp = new Microsoft.Office.Interop.Visio.Application();
                objVApp.Documents.Add(@"C:\Test\CustomTemplate\ServerTemplate.vsd");// add a document
                for (int i = 0; i < objExcelDS.Tables[0].Rows.Count; i++)
                    Visio.Page objVAPage = objVApp.ActiveDocument.Pages.Add();
                    objVApp.Documents.Add(@"C:\Test\CustomShapes\MyShapes.vss");// add a document
                    Visio.Document objVADoc = objVApp.ActiveDocument;// set the working  document to our new document
                    Visio.Masters objVMasters = objVADoc.Masters;
                    Visio.Master objVMaster = objVMasters.get_ItemU("CustomTab");
                    Visio.Shape objTabShape = objVAPage.Drop(objVMaster, 8.24d, 5.54d);
                    objTabShape.Text = objExcelDS.Tables[0].Rows[0]["VLAN"].ToString(); ;
                    //set the Shape Width
                    objTabShape.get_CellsSRC(
                            (short)Microsoft.Office.Interop.Visio.VisSectionIndices.
                            visSectionObject,
                            (short)Microsoft.Office.Interop.Visio.VisRowIndices.
                            visRowXFormIn,
                            (short)Microsoft.Office.Interop.Visio.VisCellIndices.
                            visXFormWidth).ResultIU = 16.0;
                    //set the shape height
                    objTabShape.get_CellsSRC(
                       (short)Microsoft.Office.Interop.Visio.VisSectionIndices.
                       visSectionObject,
                       (short)Microsoft.Office.Interop.Visio.VisRowIndices.
                       visRowXFormIn,
                       (short)Microsoft.Office.Interop.Visio.VisCellIndices.
                       visXFormHeight).ResultIU = 10.6;
                    Visio.Shape objOuterBox = objVAPage.DrawRectangle(dblX1, dblY1, dblX2, dblY2); // Outer Rectange
                    sFilePath = "C:\\Temp\\ServerTemplate"+i.ToString()+".vsd";
                    objVApp.ActiveDocument.SaveAsEx(@sFilePath, (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visSaveAsWS);
    but I need to generate the same visio diagram over the web application using the Response.ContentType. ie.
    context.Response.ContentType = "application/vdx.visio";
    context.Response.AddHeader("content-disposition", String.Format("attachment;filename=\"{0}.vdx\"", fileName));
    Pls give me an idea about it along with any example if possible.
    Thank you.

    Hi,
    This Visio forum is for general questions. Since your issue is related to developing, I advise you to post this issue on Office for Developer forum.
    https://social.msdn.microsoft.com/Forums/office/en-US/home?category=officedev
    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners
    who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.
    Best regards,
    Greta Ge
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

Maybe you are looking for

  • I have an iphone 4 how can I delete all my junk mail at the same time without having to selct each maessage

    How do i delete or empty all the messages in my junk email at the same time without having to mark each message?

  • Socket error.How do I fix this

    Hello all, I tried running this cleint server program that I built.This is the error I get.How do I fix this. The exception in thread isjava.net.SocketException: Software caused connection abort: recv failed Code is posted below. Thanks. Regards. nit

  • How do we?

    Hello, I want to identify the elements defined in XML schema. I have XML tables in XML DB (Oracle 9i). I tried to expand the XML tables using sqlplus Desc command. It is going in indeninete level, due to type definition for each XML elements. Do we h

  • Sych BPM scenario (RFC to SOAP)

    Hello I am using the RFC2SOAP scenario using the process shown below to get alerts. Receive  - Open S/A bridge ( Sync receive) Transform - Request_Asyn ( Mapping from RFC request to SOAP request) Sync Send - Call SOAP Transform - Response Asyn ( Mapp

  • I am unable to email pdf files. Cant print them either

    I am unable to email PDF files or print them. This happened after i upgraded my Adobe. I have deleted the program and reinstalled several times.