Plot zoom and double buffering
I have a plot program that displaces nodes and connecting lines. The nodes represent WayPoints in a region of the globe.
I initially scale the plot so that all of the nodes will show. Normally all the nodes are in a region, say the Caribbean Sea.
The Lat/Long of the WPs are converted to pixels and mapped into the display.
When I ZoomIn by X2, I change the number of pixels per degree of Lat/Long by X2 and then redraw the plot. I also allow the plot to be repositioned by click and drag with the mouse. The zooming works up to about 16X, which is adequate.
The problem is there is a small amount of flickering because I don't double buffer the image.
When I tried double buffering, I ran into problems with the createImage() method call trying to create TOO large an image after zooming in several times, The JVM runs out of space!
My question: How do I draw the WP and connecting lines when zooming?
Am I misusing the createImage() method? I'm having it create an image the size of the total zoomed area. This fails when the size of the area becomes too large!
Is there a way to use translate() or the clip area?
Why does the original Graphics context allow me to draw a plot up to about 16X with no problems?
PS. This has posted on another site. Its sort of related to another topic on this site.
Just a couple of suggestions....
I'm not sure about the zooming method you use. If I was to implement this
I would have vectorized all the elements in the map and mapped those
elements to a big internal matrix. I would have done this to avoid java
image zooming, and instead used a fixed size display image that I could
draw upon. The drawing would be of a selected subsection of this matrix,
depending on the zoming scale and positioning of the view. I would need
to get hold of the math for transposing matrix positions to a different scale
As I see it, this would facilitate implementation of huge maps and extreme
zooming, probably only limited by the amount of work that is put into the
loading/creating of the maps.
But doing this means a complete rehash of your application
You say you use createImage(), so I assume you are not using
BufferedImage but plain Image ?.
Have you tried:
BufferedImage bufImg=new BufferedImage(w,h);
A BufferedImage can be typecast to Image. I'm not sure if this will fix your
memory problem but I would have given it a try.
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center