Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

Graphics2D: How to reset a BufferedImage with an Alpha chanel

Thread view: 
charlym - 29 May 2006 08:31 GMT
Hello newsgroup!

I am trying to reset a specific area in a BufferedImage that has been
set up using an Alpha chanel (TYPE_INT_ARGB). The idea is that I have
to refresh a certain area an therefore I want to clear it before I
redraw it. Currently I am using the following code:

In the constructor:
           this.image = new BufferedImage(this.getWidth(),
this.getHeight(), BufferedImage.TYPE_INT_ARGB);
           this.dirtyHack = new BufferedImage(this.getWidth(),
this.getHeight(), BufferedImage.TYPE_INT_ARGB);

In the paintComponent method:
           image.setData(dirtyHack.getData(bounds));

This works, but it uses a lot of memory. Is there a cheaper way of
doing this?

Thanks for your help!
Thomas Weidenfeller - 29 May 2006 08:40 GMT
> I am trying to reset a specific area in a BufferedImage
[...]

> This works, but it uses a lot of memory. Is there a cheaper way of
> doing this?

image.getGraphics().clearRect(...);

Check the API doc for details.

/Thomas
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

charlym - 29 May 2006 09:03 GMT
Thomas & the rest of the newsgroup,

I tried this but it does not do what I expected. I want the rectangle
to be totally transparent. clearRect fills the rectangle with the
backgroundcolor :-( I also tried to change the color using a
transparent color (new Color(0,0,0,0)) but it did not help either.

Any other ideas?
Oliver Wong - 29 May 2006 16:14 GMT
> Thomas & the rest of the newsgroup,
>
[quoted text clipped - 4 lines]
>
> Any other ideas?

   From the javadocs:

<quote>
Beginning with Java 1.1, the background color of offscreen images may be
system dependent. Applications should use setColor followed by fillRect to
ensure that an offscreen image is cleared to a specific color.
</quote>

   Did you try that?

   - Oliver


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.