Double buffer help
- From: "Martin" <zedolf@xxxxxxxx>
- Date: Sun, 2 Apr 2006 02:07:19 +0100
I'm a newbie to Java and have today completed my first Java applet.
It's a panorama viewer which i intend to use on my website instead of
Apple's Quicktime Virtual Reality (QTVR) format.
I've used the QTVR format for a while but think that i'd get more visitors
with a Java applet - too few visitors have the QTVR browser plugin installed
and with the Quicktime installation now a massive 34.8MB i feel i'm losing
visitors because it's just too much time and hassle for an 'average' visitor
to install.
Anyway back to the point of my post....
My panorama viewer applet suffers from flickering graphics as it pans around
a panoramic image - the faster it pans, the worse the flicker.
(Image quality is acceptable with slow pan speeds however).
Here's the Paint method that i originally wrote:
public void paint(Graphics g)
{
// draw main image
g.drawImage(vrImage,panPosition,0,this);
// pad main image end to create 360 degree panoramic effect
if (panPosition<(imageWidth-displayWidth))
g.drawImage(vrImage,panPosition+imageWidth,0,this);
if (panPosition>0) g.drawImage(vrImage,panPosition-imageWidth,0,this);
}
vrImage is a JPG panoramic image with a height of 104 pixels, width varies
but averages about 1050 pixels.
panPosition is an integer that stores where in vrImage's width the viewer is
currently viewing.
imageWidth is the width of vrImage.
displayWidth is the applet width as determined within the applet tag of my
HTML page - currently it's 140 pixels.
I have a timer thread which advances the panning either way horizontally.
A mouseEntered event starts the timer, and the timer delay and pan direction
are determined by the position of the mouse over my image - it pans faster
as you move the mouse towards either left of right edge of the image.
A mouseExited event stops the timer.
All is acceptable (just!) if the panorama pans slowly, but as it pans faster
the image flickers and it looks rather unprofessional.
I've spent ages searching for a solution - use buffering, write all graphics
to a single image and then draw the single image to the screen.
Unfortunately all the tutorials and code examples i've found have been too
complex for me.
The best i have done is to rewrite my Paint method:
public void paint(Graphics g)
{
Image buffer=createImage(displayWidth,displayHeight);
Graphics bufferG=buffer.getGraphics();
bufferG.drawImage(vrImage,panPosition,0,this);
if (panPosition<(imageWidth-displayWidth))
bufferG.drawImage(vrImage,panPosition+imageWidth,0,this);
if (panPosition>0)
bufferG.drawImage(vrImage,panPosition-imageWidth,0,this);
// draw buffer to screen
g.drawImage(buffer,0,0,this);
}
The result is worse than my original (unbuffered) code!
The image degrades with just about any pan movement whatsoever, and with
fast panning the image just disappears behind the flickering.
Can anyone suggest what i can do to improve the quality of the panoramic
image?
Please remember this is my first project so my knowledge is very limited.
Thanks a lot for any help.
Martin.
--
No replies to this email address please.
.
- Follow-Ups:
- Re: Double buffer help
- From: Martin
- Re: Double buffer help
- Prev by Date: Re: integers and arrays in Java - how?
- Next by Date: Re: Double buffer help
- Previous by thread: J2ME access files??
- Next by thread: Re: Double buffer help
- Index(es):
Relevant Pages
|
|