Re: updating an ImageIcon's backing BufferedImage content from multiple
threads
cbossens73@yahoo.fr wrote:
On Apr 6, 12:48 am, Lew <no...@lewscanon.com> wrote:
Knute Johnson wrote:
...
In any case the OPs problem is easily solved by synchronizing access to
the data.
To Knute:
but on *what* should I synchronize? BufferedImage's underlying
implementation is apparently *not* synchronized.
AIUI, the advice "do all GUI work on the EDT" applies to drawing
BufferedImages, too.
It doesn't matter on what, just that access by different threads is
synchronized on the same lock. Any lock will do. Create an Object just
to use its lock or use the lock from the BufferedImage.
So in your case, the setRGB() in thread A and getRGB() in thread B,
would need to be synchronized by the same lock. The confusion comes if
you are not using getRGB() but in fact are doing something like drawing
the BufferedImage to your ImageIcon. How do you do that? You have to
call the setImage() method of ImageIcon and then call repaint(). So
synchronizing the call to setImage() (on the same lock) should be adequate.
On another note, drawing with the Java2D methods is very fast these days
and a lot less code than setting pixels. The new pipeline methods cause
a lot of that to be done in the graphics cards which are really fast.
--
Knute Johnson
email s/nospam/knute2009/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access