473,795 Members | 2,766 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(vrI mage,panPositio n,0,this);
// pad main image end to create 360 degree panoramic effect
if (panPosition<(i mageWidth-displayWidth))
g.drawImage(vrI mage,panPositio n+imageWidth,0, this);
if (panPosition>0) g.drawImage(vrI mage,panPositio n-imageWidth,0,th is);
}

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=createIm age(displayWidt h,displayHeight );
Graphics bufferG=buffer. getGraphics();
bufferG.drawIma ge(vrImage,panP osition,0,this) ;
if (panPosition<(i mageWidth-displayWidth))
bufferG.drawIma ge(vrImage,panP osition+imageWi dth,0,this);
if (panPosition>0)
bufferG.drawIma ge(vrImage,panP osition-imageWidth,0,th is);
// draw buffer to screen
g.drawImage(buf fer,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 7150

"Martin" <ze****@o2.co.u k> wrote in message
news:Ee******** *************** *******@pipex.n et...
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(vrI mage,panPositio n,0,this);
// pad main image end to create 360 degree panoramic effect
if (panPosition<(i mageWidth-displayWidth))
g.drawImage(vrI mage,panPositio n+imageWidth,0, this);
if (panPosition>0) g.drawImage(vrI mage,panPositio n-imageWidth,0,th is);
}

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=createIm age(displayWidt h,displayHeight );
Graphics bufferG=buffer. getGraphics();
bufferG.drawIma ge(vrImage,panP osition,0,this) ;
if (panPosition<(i mageWidth-displayWidth))
bufferG.drawIma ge(vrImage,panP osition+imageWi dth,0,this);
if (panPosition>0)
bufferG.drawIma ge(vrImage,panP osition-imageWidth,0,th is);
// draw buffer to screen
g.drawImage(buf fer,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.u k> wrote in
news:v7******** *************** *******@pipex.n et:

"Martin" <ze****@o2.co.u k> wrote in message
news:Ee******** *************** *******@pipex.n et...
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*****@avoidi ng.spam> wrote in message
news:Xn******** *************** *****@138.126.2 54.210...
"Martin" <ze****@o2.co.u k> wrote in
news:v7******** *************** *******@pipex.n et:

"Martin" <ze****@o2.co.u k> wrote in message
news:Ee******** *************** *******@pipex.n et...
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.u k> wrote in news:c9******** ************@pi pex.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*****@avoidi ng.spam> wrote in message
news:Xn******** *************** *****@138.126.2 54.210...
"Martin" <ze****@o2.co.u k> wrote in news:c9******** ************@pi pex.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
4458
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 menu to switch an image (actually to add rectangels offscreen and bring it to the front). The following codes runs properly. You just need to create a file images.properties and put some images in a folder called images. By the way this is...
17
12865
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. To get around this limitation on double, I'd like to keep the bits of the double the *same* but change its interpretation to long. I can use "&" on longs. I tried to use reinterpret_cast for this purpose, but it returned zero every time. double...
2
15945
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 handle all the asnychronous inputs. Someone mentioned Herb Shutters book as frame of reference, nonetheless, could someone provide sample code or - in effect an outline of double buffering? I've perused the web but most references are to...
2
3463
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 screen flicker a good bit while this happens. I'm using GDI+ and it say in MSDN that double buffering will fix this but it didnt work for me. this.Setstyle(Controlstyles.DoubleBuffer, true ); this.Setstyle(Controlstyles.UserPaint, true );...
1
3106
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 scrollable panel. Of course i've set right styles on a ChatControl: //styles this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
7
6516
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 tried as a class doesnt work.. please please help. I only need the double buffering of controls, graphics... as a class. Can anyone help me with this? Thank You so so much in advacne. I would really appreciate any help.
1
2129
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 everything ive tried as a class doesnt work.. please please help. I only need the double buffering of controls, graphics... as a class. Can anyone help me with this? Thank You so so much in advacne. I would really appreciate any help.
1
4321
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 (after converting it to a cstring), it becomes 1e+010. I've tried many different formatting ways, including stringstream formatting, sprintf(buffer, "%25.0fl", temp) - temp is the double, sprintf(buffer, "%25f", temp), etc. I am using the double...
5
3474
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 compilier warnings and then doesn't work correctly. I don't understand the warnings, sizeof(double) = 8. An integer has size 4 and it works fine. // THIS Works!!! unsigned int x_int = buffer<<24 | buffer<<16 | buffer<<8 | buffer; // This Does...
21
7524
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. sprintf (and its brothers) 3. any nonstandard C/C++ functions
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10436
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10213
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.