Chet, Thanks for the quick feed back.
Can you elaborate a bit on "pre-scaling to an intermediate image" or point me to more information on this idea. Can you also point me to some resources that discuss your 2nd suggestion: "repainting altered areas." I have the JDK documentation but it would be nice to see some examples and read a discussion of different ways to set clip areas. Thanks again, Ted Hill -----Original Message----- From: Chet Haase [mailto:[EMAIL PROTECTED] Sent: Wednesday, August 25, 2004 9:44 AM To: Ted Hill Cc: [EMAIL PROTECTED] Subject: Re: [JAVA2D] Image rendering and speed. Hi Ted, There are two approaches I can think of off the top of my head that might improve things for you: intermediate images, and repainting only what you need to. 1) Intermediate images There is no need to scale the image every time you paint it if it's the same size for some amount of time. Why not pre-scale that image to some intermediate image instead nad then simply call drawImage() from that temporary image? This copy operation will, in general, be way faster than a scaling operation (at least until we support scaling operations in hardware, which is only enabled in the non-default opengl pipeline as of jdk 5.0). 2) Repainting altered areas There is no need to tell Swing to repaint the entire image area: you can just tell it to update the region that's changed (the difference between the last mouse position and the current one, presumably). Then you will get called with a Graphics for the component with a clip set appropriately and can draw only that changed region. I think suggestion #1 above will have the biggest impact; if you don't need to transform on the fly, don't... Chet. Ted Hill wrote: > Hello, > > I am displaying a BufferedImage in a JPanel and have some questions on > performance. > > I use the AffineTransform to scale and translate the BufferedImage in > the panel. > > I also allow the user to draw on top of the image by dragging the > mouse (something like a paint program). So as the user draws on top of > the image, I need to keep calling repaint() on the panel to update the > image and the user's drawing. > > What I find is this: > > A. When my panel is relatively small (for example an 8th of total > screen area) and when the image is not scaled up (fits entirely within > the panel), I get good performance. That is, the user's drawing keeps > up with the motion of the mouse in the panel. > > B. When the panel is relatively large (say half as large as the screen > itself) and when the image is scaled way up so that it does not fit > within panel (say five times the size of the panel itself), > performance is very poor. By this I mean that the user's drawing on > top of the image lags significantly behind the movement of the mouse. > > All of my rendering is done inside of the panel's paintComponent(...) > method. > > This is how I draw the image: > > g2d.drawImage(theImage.getBufferedImage(), 0, 0, null); > > Also, I am not setting a clipping area. > > At this point I'm looking for some general advice on how to improve > performance. I'm guessing that this would involve setting a clipping > region. > > If so can some one give some specific pointers on how to set the > proper clipping region when AffineTransform has been used to scale and > pan the image so that the image is much larger than the panel itself. > > Thank you, > > Ted Hill > ====================================================================== > ===== > To unsubscribe, send email to [EMAIL PROTECTED] and include in the > body of the message "signoff JAVA2D-INTEREST". For general help, send > email to [EMAIL PROTECTED] and include in the body of the message > "help". =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA2D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".