473,385 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Double buffer help

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.
Apr 2 '06 #1
5 7126

"Martin" <ze****@o2.co.uk> wrote in message
news:Ee******************************@pipex.net...
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.


For anyone interested i've created a temporary webpage where you can see
both my original code and the supposedly buffered code in action!

http://www.warwound.dsl.pipex.com/applet/panViewer.htm

Martin.
Apr 2 '06 #2
"Martin" <ze****@o2.co.uk> wrote in
news:v7******************************@pipex.net:

"Martin" <ze****@o2.co.uk> wrote in message
news:Ee******************************@pipex.net...
I'm a newbie to Java and have today completed my first Java applet.
<snip>
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).

<snip>

You don't say what component your Paint() method is in.
You don't say how you are causing the image to be redrawn.

I will guess that you are calling repaint(...). If I recall correctly,
repaint actually causes update(...) to be called. The default action for
update is to clear the drawing area, and then call paint(...).

You may need to override update to call paint directly.

.... or I may be completely off base, reasoning from insufficient information.
Source code would be nice.
--
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *
Apr 3 '06 #3

"Ian Shef" <in*****@avoiding.spam> wrote in message
news:Xn****************************@138.126.254.21 0...
"Martin" <ze****@o2.co.uk> wrote in
news:v7******************************@pipex.net:

"Martin" <ze****@o2.co.uk> wrote in message
news:Ee******************************@pipex.net...
I'm a newbie to Java and have today completed my first Java applet.
<snip>
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).

<snip>

You don't say what component your Paint() method is in.
You don't say how you are causing the image to be redrawn.

I will guess that you are calling repaint(...). If I recall correctly,
repaint actually causes update(...) to be called. The default action for
update is to clear the drawing area, and then call paint(...).

You may need to override update to call paint directly.

... or I may be completely off base, reasoning from insufficient
information.
Source code would be nice.
--
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *

Brilliant!

Yep my timer thread was calling repaint().
I had a quick Google and found an example of using the update() method.

I simply duplicated the code from my paint() method in the update() method
and gave that a try and it's perfect.
The flicker has disappeared.

I've updated the temporary webpage too - both the old (flickering) applet
and the new improved applet can both be seen in action.
http://www.warwound.dsl.pipex.com/applet/panViewer.htm

Thanks a lot - very easy and quick for me to fix it once i was pointed in
the right direction.

Martin.
Apr 3 '06 #4
"Martin" <ze****@o2.co.uk> wrote in news:c9********************@pipex.net:

Brilliant!
No, but thanks.
Yep my timer thread was calling repaint().
I had a quick Google and found an example of using the update() method.
An excellent resource for painting issues is
"Painting in AWT and Swing":

http://java.sun.com/products/jfc/tsc...ing/index.html


I simply duplicated the code from my paint() method in the update()
method and gave that a try and it's perfect. Nooooooooooooo !!

You are setting yourself up for a maintenance and debug nightmare.
Provide the code in only ONE place!
Either:
1) Locate the code in paint(), and have update() call paint(), OR
2) Locate the code in update(), and have paint() call update(), OR
3) Locate the code in a new method, and have both paint() and update(0
call the new method.
The flicker has disappeared.
Glad to hear it.
I've updated the temporary webpage too - both the old (flickering)
applet and the new improved applet can both be seen in action.
http://www.warwound.dsl.pipex.com/applet/panViewer.htm
Nice contrast between the two cases. Thanks, I rarely get to see such a
visible result of my advice.
Thanks a lot - very easy and quick for me to fix it once i was pointed
in the right direction.

Martin.

Happy to have helped.
-- Ian

--
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *
Apr 5 '06 #5

"Ian Shef" <in*****@avoiding.spam> wrote in message
news:Xn****************************@138.126.254.21 0...
"Martin" <ze****@o2.co.uk> wrote in news:c9********************@pipex.net:

Brilliant!


No, but thanks.

Yep my timer thread was calling repaint().
I had a quick Google and found an example of using the update() method.


An excellent resource for painting issues is
"Painting in AWT and Swing":

http://java.sun.com/products/jfc/tsc...ing/index.html


I simply duplicated the code from my paint() method in the update()
method and gave that a try and it's perfect.

Nooooooooooooo !!

You are setting yourself up for a maintenance and debug nightmare.
Provide the code in only ONE place!
Either:
1) Locate the code in paint(), and have update() call paint(), OR
2) Locate the code in update(), and have paint() call update(), OR
3) Locate the code in a new method, and have both paint() and update(0
call the new method.
The flicker has disappeared.


Glad to hear it.

I've updated the temporary webpage too - both the old (flickering)
applet and the new improved applet can both be seen in action.
http://www.warwound.dsl.pipex.com/applet/panViewer.htm


Nice contrast between the two cases. Thanks, I rarely get to see such a
visible result of my advice.

Thanks a lot - very easy and quick for me to fix it once i was pointed
in the right direction.

Martin.

Happy to have helped.
-- Ian

--
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *


Thanks for the advice about duplicating the drawing code.

I've rewritten my applet and created a new method which i've called
displayRedraw() and moved the code to that method.
Then both paint() and update() methods merely call my new displayRedraw()
method and all works as before - even makes the compiled class file a very
little bit smaller too.

I'll take a look at the "Painting in AWT and Swing" link later when i have
more time.

Thanks again.

Martin.
Apr 6 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David | last post by:
Hello I'm writting an apllication and i like to display and offscreen image. However my code doesn't seem to work. It compiles and runs properly but What i want is to associate the button of the...
17
by: Suzanne Vogel | last post by:
I'd like to convert a double to a binary representation. I can use the "&" bit operation with a bit mask to convert *non* float types to binary representations, but I can't use "&" on doubles. ...
2
by: MPowell | last post by:
Gents/Ladies, I'm doing (at least plan on ) lots of Reads and Writes across a communication channel. I'm told that for the 'receive side' it'd be prudent to implement a double buffering scheme to...
2
by: Jason | last post by:
I have created a 2d isometric game map using tiles and now I'm trying to move around my map..when i go near the edge of the map I want to redraw the map to show new parts of the map however the...
1
by: Kuba Florczyk | last post by:
Hi I've got some problem doing double buffer. Here is my problem: I've got custom control on which i paint some data (chat messages, lets call it ChatControl), this control is puted on a...
7
by: Rain | last post by:
Hello Gurus! I really need this one to finish a module in my thesis. PLease please help me. I need a double buffer class so i can call it and use it anytime i want, the problem is everything ive...
1
by: Rain | last post by:
Hello Gurus! I really need this one to finish a module in my thesis. PLease please help me. I need a double buffer class in C# so i can call it and use it anytime i want, the problem is...
1
by: bsmith1111 | last post by:
I have a program that outputs the following to the screen (through visual c++) 9999999999, which is stored in a double. I would like to keep the number the way it is, but every time I output it...
5
by: DBuss | last post by:
I'm trying to convert a binary data feed into something more friendly. Some of the data is Int (and extracts successfully), but some is Double and doesn't. The below line of code gives harsh...
21
by: Aman JIANG | last post by:
hi I need to do this (convert double to string) fast, safe and portable. Is there any way to do this ? Except the ways following: 1. C++ I/O stream, stringstream (and boost::lexical_cast) 2....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.