• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How optimize paintComponent?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm developing an application that draw a shape over an image and then after clic a button, the application calculate all the points that are into the shape and paint it with the same color as the shape.
I paint the shape in the paintComponent method. My problem is that performance of the application descends dramatically in the moment that have to repaint all this points. How can I increase the performance?

I have the rectangle that includes the shape and I use a byte[] to store the points (1 are into the shape, 0 are out).

Thank's a lot.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using the shape to set the clip for the graphics context and then draw the image.

The image pixels that fall inside the clipping shape should be the only ones rendered.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And for painting the image in a different color, take a look at the class RGBImageFilter.
 
joan wo
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Thank's a lot for your replies.

I have two doubts:
- In the shape I only have the points of the border of the shape. I have to find all the points of the interior of the shape, is in this process when the process is too slow. How can I use the setClip method to obtain the points of the interior?
- Is possible to call paintComponent (with reapint) only when there are a change on the image. I've tried to do it, but then the shape is not ever repaint it, and disappears.

Thank's.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
reply
    Bookmark Topic Watch Topic
  • New Topic